Use different colormaps for pcolor subplots

6 vues (au cours des 30 derniers jours)
Heidi Hirsh
Heidi Hirsh le 16 Juil 2019
Commenté : Adam Danz le 17 Juil 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 commentaires
Walter Roberson
Walter Roberson le 16 Juil 2019
Which MATLAB release are you using?
Heidi Hirsh
Heidi Hirsh le 16 Juil 2019
R2018b

Connectez-vous pour commenter.

Réponse acceptée

Adam Danz
Adam Danz le 16 Juil 2019
Modifié(e) : Adam Danz le 16 Juil 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.
  2 commentaires
Heidi Hirsh
Heidi Hirsh le 16 Juil 2019
This worked! Thank you!
Adam Danz
Adam Danz le 17 Juil 2019
Glad I could help!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Colormaps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by