Different colormaps for subplots

조회 수: 709 (최근 30일)
Heidi Hirsh
Heidi Hirsh 2019년 8월 23일
댓글: mohsen qutbi 2023년 1월 19일
I am having a frustrating problem that I think is related to how I am using handles to format the colormaps in my plots. I am trying to plot the first two subplots with the bluewhitered colormap to emphasize the positive versus negative values. But I want the third subplot (temperature) to use the jet colormap. When I run the full script for my figure I get jet coloring for all three. But if I only run the first subplots I get the coloring I want. Is there something in my code for the third subplot that is changing the first two? Please see figures for clarification. Thank you so much!
Here's my code:
f1=figure(1)
%PK alongshore
ax(1) = subplot(3,1,1)
hold on
pcolor(PK1.time,PK1.zbin,PK1.pE'); %Plot velocity
pcolor(PK2.time,PK2.zbin,PK2.pE');
plot(PK1.time,PK1.depth,'k'); %Plot depth
plot(PK2.time,PK2.depth,'k');
shading('flat'); caxis([-0.05 0.05]);
a=colorbar; colormap(bluewhitered);
set(a, 'Position', [0.93 .72 .015 .2])
set(get(a,'label'),'string','Alongshore','fontsize',14);
%legend('Current Alongshore (m/s)','Depth (m)');
%legend('Alongshore Velocity (m/s)')
set(gca,'fontsize',16)
ylabel('Depth (m)');
ylim([0 11]);
x = datenum('June-4-2018'):7:datenum('Oct-10-2018');
set(gca, 'XTick', x);
datetick('x','mm/dd','keepticks')
%PK cross-shore
ax(2) = subplot(3,1,2)
hold on
pcolor(PK1.time,PK1.zbin,PK1.pN'); %Plot velocity
pcolor(PK2.time,PK2.zbin,PK2.pN');
plot(PK1.time,PK1.depth,'k'); %Plot depth
plot(PK2.time,PK2.depth,'k');
shading('flat'); caxis([-0.05 0.05]);
b=colorbar; colormap(bluewhitered);
set(b, 'Position', [0.93 .42 .015 .2])
set(get(b,'label'),'string','Cross-shore','fontsize',14);
set(gca,'fontsize',16)
ylabel('Depth (m)');
ylim([0 11]);
x = datenum('June-4-2018'):7:datenum('Oct-10-2018');
set(gca, 'XTick', x);
datetick('x','mm/dd','keepticks')
%PK Temperature
ax(3) = subplot(3,1,3)
h=plot(MX,PK.PRESS(9,:),'k')
hold on
pcolor(MX,PK.mab,PK.TEMP); %Plot temperature
shading('interp');
ylabel('Depth (mab)');
c=colorbar; colormap(jet);
set(c, 'Position', [0.93 .11 .015 .2])
caxis([9 19.2]);
title(c,'\circC','fontsize',18);
set(gca,'fontsize',16);
x = datenum('June-4-2018'):7:datenum('Oct-10-2018');
set(gca, 'XTick', x);
datetick('x','mm/dd','keepticks');
linkaxes(ax,'x')

채택된 답변

Vishnurajan
Vishnurajan 2019년 8월 23일
Hi,
please try
colormap(ax(1),bluewhitered)
colormap(ax(2),spring)
colormap(ax(3),jet)
  댓글 수: 3
NEHA SINGH
NEHA SINGH 2022년 8월 23일
Thanks for the help.
mohsen qutbi
mohsen qutbi 2023년 1월 19일
thanks a lot

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Louisa Waasmann
Louisa Waasmann 2020년 5월 26일
Hi,
actually, I have exactly the same question, but
colormap(ax,cMap);
does not solve my problem. I get an error message "Unable to use a value of type matlab.graphics.axis.Axes as an index." but have no clue how to fix it. A minimal example can be found below.
Thank you very much!
%Create an image of 2 subplots with the same colorscale but different colormaps
colorscale=[0 1];
Overview= figure('units','normalized','position',[.0 .0 1 0.9])
ax1 = subplot(1,2,1);
colormap(ax1,parula) % Error message is related to this line
ibg = imagesc(A, colorscale);
axis off
title('1')
ax2 = subplot(1,2,2);
colormap(ax2,spring)
iim = imagesc(B, colorscale);
axis off
title('2')
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 5월 27일
You accidentally created a variable named colormap so MATLAB thinks you are trying to index that variable.
Louisa Waasmann
Louisa Waasmann 2020년 5월 27일
I didn't realize that. Thanks a lot!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by