Overlay imagesc and contour in subplot with different colour bars

조회 수: 7 (최근 30일)
Hugo Fortescue
Hugo Fortescue 2021년 3월 17일
편집: Adam Danz 2021년 3월 22일
Hi All,
I have an image i would like to produce as part of an array of 6, and I have the following code:
Unwrap = subplot(2,3,5);
hold on
imagesc(G_Unwrapped); title('Phase Change');colorbar, axis square
colormap(Unwrap,'gray')
contour(G_Unwrapped, 'ShowText','on');
hold off
However, as the axis handle applies to the whole subplot, and not the indervidual plot commands I can't think of a way to apply a second colour map too the contour plot.
Many thanks in advanced for any help!

채택된 답변

Adam Danz
Adam Danz 2021년 3월 17일
편집: Adam Danz 2021년 3월 17일
> the axis handle applies to the whole subplot, and not the indervidual plot commands
That's correct. A workaround is to assign two overlapping axes with care so that the axes are linked.
Follow this demo that carefully overlays imagesc and contour
You can easily add two independent colobars to the example above following this similar example,
Give it a shot and if you get stuck, show us what you've got and I can nudge you in the right direction.
  댓글 수: 2
Hugo Fortescue
Hugo Fortescue 2021년 3월 18일
Hi there,
Thanks for those links. I have manged to follow them to get a single figure with 2 colourscales, but I'm not sure how to make it work for a subplot instead.
Wrap = subplot(2,3,5);
ax1 = axes(Wrap);
ax2 = copyobj(ax1,Wrap);
This spits out a "Too many output arguments" error message
Adam Danz
Adam Danz 2021년 3월 18일
편집: Adam Danz 2021년 3월 22일
This line doesn't make sense. Wrap is the axis handle.
ax1 = axes(Wrap);
The first 3 lines in the first link in my answer should look like this for subplots,
fig = clf();
ax1 = subplot(___);
ax2 = copyobj(ax1,fig);
% then continue with the demo in the link
I tested that full solution using subplots in r2021a and it works well.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by