フィルターのクリア

Change colorbar scale, but keep zero value white

105 ビュー (過去 30 日間)
Heidi Hirsh
Heidi Hirsh 2019 年 8 月 14 日
コメント済み: Jess Lovering 2019 年 8 月 15 日
I am trying to plot positive data as red (darker red=higher magnitude) and negative data as blue. I want zero to be white. I am using the bluewhitered function to color the data because I could not have another colormap that did this in the matlab choices. But since my data include much higher positive magnitudes than negative values. The negatives look dark blue even at low magnitude. I think the function must make the max and min data values the darkest color end points. I tried to force the negative data to show up lighter blue by using caxis to limit the colors from -0.5 to +0.5 but then zero is not white for some reason. Do you have another idea for a similar color map or a way to fix this one?
I have attached the first plot and my attempted fix.
Here's my code:
f1=figure(1)
pcolor(MX,PK.mab,PK.fixdeltaPH);
shading('interp');
colormap(bluewhitered);
ylabel('Depth (mab)','fontsize',16);
c=colorbar();
%caxis([-0.5 0.5]); % This did not fix it because zero is not white now
ylim([0 6])
title(c,'\DeltapH','fontsize',16);
set(gca,'fontsize',16);
x = datenum('July-23-2018'):7:datenum('Oct-5-2018');
set(gca, 'XTick', x);
datetick('x','mm/dd','keepticks')
  3 件のコメント
Heidi Hirsh
Heidi Hirsh 2019 年 8 月 14 日
Try loading this mat file and running this:
load data % includes times, dephts, and delta pH values
f1=figure(1)
%pcolor(MX,PK.mab,PK.fixdeltaPH);
pcolor(times,depths,delPH);
shading('interp');
colormap(bluewhitered);
ylabel('Depth (mab)','fontsize',16);
c=colorbar();
%caxis([-0.5 0.5]);
ylim([0 6])
title(c,'\DeltapH','fontsize',16);
set(gca,'fontsize',16);
x = datenum('July-23-2018'):7:datenum('Oct-5-2018');
set(gca, 'XTick', x);
datetick('x','mm/dd','keepticks')
Jess Lovering
Jess Lovering 2019 年 8 月 14 日
I ran your test script and it looks like it worked OK for me. The zero values were white on my plot.

サインインしてコメントする。

採用された回答

Heidi Hirsh
Heidi Hirsh 2019 年 8 月 14 日
Yes it works if I don't include (currently commented out) the caxis line. The issue is the negatives look more extreme since the minimum data value is automatically the darkest blue. It is when I use the caxis([-0.5 0.5]) line (to try to better distribute shading) that I get non-white zero. White ends up being between -2.0 and -3.0 on the color bar (see 'attempted_fix.png'). Thank you!
  3 件のコメント
Heidi Hirsh
Heidi Hirsh 2019 年 8 月 14 日
That worked! Thank you so much!
Jess Lovering
Jess Lovering 2019 年 8 月 15 日
Excellent! Glad to help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeRed についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by