MATLAB Answers

Use different colormaps for pcolor subplots

10 ビュー (過去 30 日間)
Heidi Hirsh
Heidi Hirsh 2019 年 7 月 16 日
Commented: Adam Danz 2019 年 7 月 17 日
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 件のコメント

Walter Roberson
Walter Roberson 2019 年 7 月 16 日
Which MATLAB release are you using?
Heidi Hirsh
Heidi Hirsh 2019 年 7 月 16 日
R2018b

サインイン to comment.

採用された回答

Adam Danz
Adam Danz 2019 年 7 月 16 日
編集済み: Adam Danz 2019 年 7 月 16 日
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 件のコメント

Heidi Hirsh
Heidi Hirsh 2019 年 7 月 16 日
This worked! Thank you!
Adam Danz
Adam Danz 2019 年 7 月 17 日
Glad I could help!

サインイン to comment.

More Answers (0)

サインイン してこの質問に回答します。


Translated by