Overlap two pcolor with different color and set up transparency

42 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Chad Greene
Chad Greene am 23 Feb. 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 Kommentare
Alexander Audet
Alexander Audet am 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 am 7 Sep. 2022
Historically there could only be one colormap for each figure, but that was changed eventually to permit one colormap per axes.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Orange finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by