Use different colormaps for pcolor subplots

5 views (last 30 days)
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');

Accepted Answer

Adam Danz
Adam Danz on 16 Jul 2019
Edited: Adam Danz on 16 Jul 2019
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.

More Answers (0)

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!