Overlay imagesc and contour in subplot with different colour bars

13 vues (au cours des 30 derniers jours)
Hugo Fortescue
Hugo Fortescue le 17 Mar 2021
Modifié(e) : Adam Danz le 22 Mar 2021
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!

Réponse acceptée

Adam Danz
Adam Danz le 17 Mar 2021
Modifié(e) : Adam Danz le 17 Mar 2021
> 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 commentaires
Hugo Fortescue
Hugo Fortescue le 18 Mar 2021
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 le 18 Mar 2021
Modifié(e) : Adam Danz le 22 Mar 2021
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by