MATLAB Answers

Colorbar With Wrong Graphs

6 views (last 30 days)
Peter Sakkos
Peter Sakkos on 1 May 2021
Commented: VBBV on 1 May 2021
I have a function that, when executed, creates two plots, both of which have different colormaps and colorplots. When I run my code, the first figure gets printed first, correctly, with the right color scheme and color bar shown. Then, when the 2nd figure shows, the first figure shows what is supposed to be the second color bar. The second figure also shows some random color bar. How can I pin each color to a specific figure so that this switching/ flip-flopping doesn't happen?
  2 Comments
Peter Sakkos
Peter Sakkos on 1 May 2021
My actual code is fairly long due to all of the plotting features I have.
It basically goes as follows. When it runs, colorbar "s" goes to figure 1 and the default colorbar goes to figure 2:
figure(1)
plot(...)
cm_P = colormap(summer(length(psi)));
p = colorbar;
...
figure(2)
plot(...)
cm_T = colormap(winter(length(psi)));
s = colorbar;

Sign in to comment.

Answers (1)

VBBV
VBBV on 1 May 2021
%if true
figure(1)
plot(...)
ax1 = gca
cm_P = colormap(ax1,summer(length(psi)));
p = colorbar;
...
figure(2)
plot(...)
ax2 = gca
cm_T = colormap(ax2,winter(length(psi)));
s = colorbar;
Try with axis handles
  3 Comments
VBBV
VBBV on 1 May 2021
Ok. Great

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by