MATLAB Answers

0

Use different colormaps for pcolor subplots

Asked by Heidi Hirsh on 16 Jul 2019
Latest activity Commented on by Adam Danz
on 17 Jul 2019
Hi! I'm trying to plot two subplot with different color scales. I finally made the colorbars the correct colors but now my data is using an entirely different colormat. Does anyone know how to fix this so the data is still shown with the jet colors (low=red for subplot 1 and low=blue for subplot 2)? Thank you in advance!
This is my code for the first two subplots:
ax(1) = subplot(4,1,1)
plot(MX,PK.PRESS(9,:),'color',[.8 .8 .8]);
hold on
pcolor(MX,PK.mab,PK.fixPH);
shading('interp');
ylabel('Depth (mab)','fontsize',16);
c=colorbar; colormap(c,flipud(jet)) %color scale should be flipped!
set(c, 'Position', [0.93 .76 .015 .15])
title(c,'pH','fontsize',16);
% ylim([0 6.1])
set(gca,'fontsize',14);
title('PK Mooring')
x = datenum('June-4-2018'):7:datenum('Oct-8-2018');
set(gca, 'XTick', x);
datetick('x','mm/dd','keepticks')
ax(2) = subplot(4,1,2)
pcolor(MX,PK.mab,PK.TEMP); %temperature
% shading('interp');
shading('flat');
ylabel('Depth (mab)','fontsize',20);
d=colorbar; colormap(d,jet);
caxis([9 19.2]);
title(d,'T (\circC)','fontsize',18);
set(d, 'Position', [0.93 .54 .015 .15]) %Set position as [left, bottom, width, height] %this is right middle
set(gca,'fontsize',14);
% title('PK Temperature')
x = datenum('June-4-2018'):7:datenum('Oct-8-2018');
set(gca, 'XTick', x);
datetick('x','mm/dd','keepticks');

  2 Comments

Which MATLAB release are you using?

Sign in to comment.

1 Answer

Answer by Adam Danz
on 16 Jul 2019
Edited by Adam Danz
on 16 Jul 2019
 Accepted Answer

You're assigning the colormap to the colorbar. Instead, assign it to the axes and the colorbar will follow suit.
ax(1) = subplot(4,1,1)
plot(MX,PK.PRESS(9,:),'color',[.8 .8 .8]);
hold on
pcolor(MX,PK.mab,PK.fixPH);
shading('interp');
ylabel('Depth (mab)','fontsize',16);
c=colorbar();
colormap(ax(1),flipud(jet)) % <---- axis handle in input #1
% * NOT TESTED
If necesary, use caxis() to scale the color range.

  2 Comments

This worked! Thank you!
Glad I could help!

Sign in to comment.