Overlap two pcolor with different color and set up transparency

70 views (last 30 days)
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

Accepted Answer

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

Sign in to comment.

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!