Different colormaps for subplots

685 views (last 30 days)
I am having a frustrating problem that I think is related to how I am using handles to format the colormaps in my plots. I am trying to plot the first two subplots with the bluewhitered colormap to emphasize the positive versus negative values. But I want the third subplot (temperature) to use the jet colormap. When I run the full script for my figure I get jet coloring for all three. But if I only run the first subplots I get the coloring I want. Is there something in my code for the third subplot that is changing the first two? Please see figures for clarification. Thank you so much!
Here's my code:
f1=figure(1)
%PK alongshore
ax(1) = subplot(3,1,1)
hold on
pcolor(PK1.time,PK1.zbin,PK1.pE'); %Plot velocity
pcolor(PK2.time,PK2.zbin,PK2.pE');
plot(PK1.time,PK1.depth,'k'); %Plot depth
plot(PK2.time,PK2.depth,'k');
shading('flat'); caxis([-0.05 0.05]);
a=colorbar; colormap(bluewhitered);
set(a, 'Position', [0.93 .72 .015 .2])
set(get(a,'label'),'string','Alongshore','fontsize',14);
%legend('Current Alongshore (m/s)','Depth (m)');
%legend('Alongshore Velocity (m/s)')
set(gca,'fontsize',16)
ylabel('Depth (m)');
ylim([0 11]);
x = datenum('June-4-2018'):7:datenum('Oct-10-2018');
set(gca, 'XTick', x);
datetick('x','mm/dd','keepticks')
%PK cross-shore
ax(2) = subplot(3,1,2)
hold on
pcolor(PK1.time,PK1.zbin,PK1.pN'); %Plot velocity
pcolor(PK2.time,PK2.zbin,PK2.pN');
plot(PK1.time,PK1.depth,'k'); %Plot depth
plot(PK2.time,PK2.depth,'k');
shading('flat'); caxis([-0.05 0.05]);
b=colorbar; colormap(bluewhitered);
set(b, 'Position', [0.93 .42 .015 .2])
set(get(b,'label'),'string','Cross-shore','fontsize',14);
set(gca,'fontsize',16)
ylabel('Depth (m)');
ylim([0 11]);
x = datenum('June-4-2018'):7:datenum('Oct-10-2018');
set(gca, 'XTick', x);
datetick('x','mm/dd','keepticks')
%PK Temperature
ax(3) = subplot(3,1,3)
h=plot(MX,PK.PRESS(9,:),'k')
hold on
pcolor(MX,PK.mab,PK.TEMP); %Plot temperature
shading('interp');
ylabel('Depth (mab)');
c=colorbar; colormap(jet);
set(c, 'Position', [0.93 .11 .015 .2])
caxis([9 19.2]);
title(c,'\circC','fontsize',18);
set(gca,'fontsize',16);
x = datenum('June-4-2018'):7:datenum('Oct-10-2018');
set(gca, 'XTick', x);
datetick('x','mm/dd','keepticks');
linkaxes(ax,'x')

Accepted Answer

Vishnurajan
Vishnurajan on 23 Aug 2019
Hi,
please try
colormap(ax(1),bluewhitered)
colormap(ax(2),spring)
colormap(ax(3),jet)

More Answers (1)

Louisa Waasmann
Louisa Waasmann on 26 May 2020
Hi,
actually, I have exactly the same question, but
colormap(ax,cMap);
does not solve my problem. I get an error message "Unable to use a value of type matlab.graphics.axis.Axes as an index." but have no clue how to fix it. A minimal example can be found below.
Thank you very much!
%Create an image of 2 subplots with the same colorscale but different colormaps
colorscale=[0 1];
Overview= figure('units','normalized','position',[.0 .0 1 0.9])
ax1 = subplot(1,2,1);
colormap(ax1,parula) % Error message is related to this line
ibg = imagesc(A, colorscale);
axis off
title('1')
ax2 = subplot(1,2,2);
colormap(ax2,spring)
iim = imagesc(B, colorscale);
axis off
title('2')
  2 Comments
Walter Roberson
Walter Roberson on 27 May 2020
You accidentally created a variable named colormap so MATLAB thinks you are trying to index that variable.
Louisa Waasmann
Louisa Waasmann on 27 May 2020
I didn't realize that. Thanks a lot!

Sign in to comment.

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!