Overlap two pcolor with different color and set up transparency

조회 수: 66 (최근 30일)
Xin
Xin 2017년 2월 22일
댓글: Walter Roberson 2022년 9월 7일
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
Shaibal Ahmed
Shaibal Ahmed 2017년 2월 22일
I have a similar question, would be great if someone could answer it.

댓글을 달려면 로그인하십시오.

채택된 답변

Chad Greene
Chad Greene 2017년 2월 23일
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
Alexander Audet
Alexander Audet 2022년 9월 7일
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 2022년 9월 7일
Historically there could only be one colormap for each figure, but that was changed eventually to permit one colormap per axes.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by