Use different colormaps for pcolor subplots
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
Réponse acceptée
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
2 commentaires
Plus de réponses (0)
Voir également
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!