Contourf plot in discrete range

I have a matrix the values of which ranges from ~0.000001 to ~0.004. I want to separate the colors like this.. 1e-6 to 2e-6 (one color), 2e-6 to 5e-6 (next color), then 5e-6 to 1e-5, 1e-5 to 2e-5, 2e-5 to 5e-5, 5e-5 to 1e-4, 1e-4 to 2e-4, 2e-4 to 5e-4, 5e-4 to 1e-3, 1e-3 to 2e-3, 2e-3 to 3e-3, then 3e-3 to higher values. Here, 1e-6 = 0.000001. Somehow I managed to give different range of values to different colors, but the whole discrete set of ranges is not showed up in the caxis. It only showed discrete range in caxis for values higher than 0.0005, values below that, i.e. 0 to 0.0005 shown only by a single color. Similar to the attached picture is what I want..Could anyone please help..?? Thanks in advance

回答 (2 件)

KSSV
KSSV 2018 年 8 月 7 日
編集済み: KSSV 2018 年 8 月 7 日

0 投票

[Z,txt,raw] = xlsread('data.xlsx') ;
Z(Z==-9999) = NaN ;
pcolor(Z) ;
shading interp
colorbar
%%Fix Ranges
R = [5e-6 1e-5 ;1e-5 2e-5; 2e-5 5e-5; 5e-5 1e-4; 1e-4 2e-4;2e-4 5e-4; 5e-4 1e-3; 1e-3 2e-3; 2e-3 3e-3 ;3e-3 inf] ;
C = rand(size(R,1),3) ; % fix random colors, you can use your custom RGB colors here
A = Z ;
for i = 1:size(R,1)
idx = Z>=R(i,1) & Z< R(i,2) ;
A(idx) = R(i,2) ;
end
figure
shading interp
pcolor(A)
shading interp
colorbar
colormap(C)

5 件のコメント

Bijay Guha
Bijay Guha 2018 年 8 月 7 日
編集済み: Bijay Guha 2018 年 8 月 7 日
Thanks for your kind effort. But as I said before this is not working for the data ranges below 0.0005. Its simply gives one color to the data below this value (0.0005), which is not desire. I need more division of color between 0.0005 to 0.000001 as I mentioned before, and is also shown by the image attached (Picture1.png). I am sharing the example data contains your X Y and Z, with fill value -9999, and the data less than 0.000001 prefer to be white in color. And the range is
[-inf 0.000001; 0.000001 0.000002; 0.000002 0.000005; 0.000005 0.00001; ...
0.00001 0.00002; 0.00002 0.00005; 0.00005 0.0001;...
0.0001 0.0002; 0.0002 0.0005; 0.0005 0.001; 0.001 0.002; 0.002 0.003; 0.003 inf] ;
Thank You
KSSV
KSSV 2018 年 8 月 7 日
Edited the code...check now..is it okay?
Bijay Guha
Bijay Guha 2018 年 8 月 7 日
No. It still gives only two colors for the values less than 0.0005. Please see this image
KSSV
KSSV 2018 年 8 月 7 日
YOu try changing the ranges in R
Bijay Guha
Bijay Guha 2018 年 8 月 7 日
but I need those ranges only

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

Marco Sandoval
Marco Sandoval 2019 年 3 月 1 日

0 投票

Hi..
I have the same question. Any luck?
The solution given above is not 100% correct, because it is changing the real values to the upper limit of each range, and when you do a pcolor graph, it doesn't looks like the original.. instead it's seems very rude, as low resolution.
Is there a way of manage the range of numbers of each color in a discrete palette? I mean, something like:
between -inf and 20, one color (considering all real numbers in between)
between 20 and 40, other color
... etc.
I have seen solutions but with surf and scatter functions (because they have an option for colors), but I'm asking for pcolor or contourf.
regards!

1 件のコメント

Walter Roberson
Walter Roberson 2019 年 3 月 1 日
編集済み: Walter Roberson 2019 年 3 月 1 日
pcolor() is implemented as surf() followed by view(2) . However, pcolor() accepts very few options.

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

カテゴリ

ヘルプ センター および File ExchangeContour Plots についてさらに検索

質問済み:

2018 年 8 月 4 日

編集済み:

2019 年 3 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by