Overlap two pcolor with different color and set up transparency

38 vues (au cours des 30 derniers jours)
Xin
Xin le 22 Fév 2017
I have two figures like below.
What I want to do is 1) overlap them into one figure. 2) set transparency at the place where they meet each other. The colour can be changed, can be any color where an overlap will look nice.
Many thanks
  1 commentaire
Shaibal Ahmed
Shaibal Ahmed le 22 Fév 2017
I have a similar question, would be great if someone could answer it.

Connectez-vous pour commenter.

Réponse acceptée

Chad Greene
Chad Greene le 23 Fév 2017
What about this?
% Some sample data:
[X,Y,Z1] = peaks;
Z2 = flipud(Z1);
% Blue layer:
p1 = surf(X,Y,zeros(size(Z1)),'AlphaData',Z1,...
'FaceAlpha','interp',...
'FaceColor','blue',...
'edgecolor','none');
% Red layer:
hold on
p2 = surf(X,Y,zeros(size(Z2)),'AlphaData',Z2,...
'FaceAlpha','interp',...
'FaceColor','red',...
'edgecolor','none');
view(2)
grid off
  3 commentaires
Alexander Audet
Alexander Audet le 7 Sep 2022
Yes, just figured this out. You need to put them on separate axes, then turn off the second axis visibility:
% Some sample data:
[X,Y,Z1] = peaks;
Z2 = flipud(Z1);
figure
%Create the first axis and colormap
ax1 = axes;
hold on
colormap(ax1, hot)
% Plot on first axis
h1 = surf(ax1,X,Y,zeros(size(Z1)),Z1,'edgecolor','none')
%Create the second axis and colormap
ax2 = axes;
hold on
colormap(ax2, winter)
% Plot on second axis
h2 = surf(ax2,X,Y,zeros(size(Z2)),Z2,'edgecolor','none', 'FaceAlpha', 0.5)
% Turn 3D surface into 2D surface (map view)
view(2)
grid off
%Turn off ax2 so you can see the first plot
ax2.Visible = 'off';
ax2.XTick = [];
ax2.YTick = [];
Walter Roberson
Walter Roberson le 7 Sep 2022
Historically there could only be one colormap for each figure, but that was changed eventually to permit one colormap per axes.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Orange dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by