フィルターのクリア

How do I bind a specific value to a color using colormap?

34 ビュー (過去 30 日間)
Denis Perotto
Denis Perotto 2019 年 1 月 15 日
回答済み: Walter Roberson 2019 年 1 月 16 日
I'm plotting a 2D contour plot using contourf(X, Y, Z). How can I create a custom colormap, where certain color would be bound to a curtain value? For example:
100 - [1 0 0]
200 - [1 0.5 0]
1000 - [1 1 0]
It would be also nice to make all values below 100, for example, [0.5 0 0] and all values above 1000 - [1 1 0.5].
Please, do not suggest colormap editor. If this task is impossible for colormap, suggest me another function for 2D plots (maybe, plot it dot by dot)
  2 件のコメント
Walter Roberson
Walter Roberson 2019 年 1 月 16 日
To confirm: if the input value were 100*(1+eps) then the output should be transparent because the value would not be any of the ones you listed?
Denis Perotto
Denis Perotto 2019 年 1 月 16 日
I meant non-even intervals:
-inf ... 100 - [0.5 0 0]
100-200 - [1 0 0]
200-1000 - [1 0.5 0]
1000 ... inf - [1 1 0]

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

採用された回答

Walter Roberson
Walter Roberson 2019 年 1 月 16 日

その他の回答 (1 件)

KSSV
KSSV 2019 年 1 月 15 日
  1 件のコメント
Denis Perotto
Denis Perotto 2019 年 1 月 16 日
編集済み: Denis Perotto 2019 年 1 月 16 日
Tricky, but not acceptable for me.
First, there is a need to see real, not modified, data at any point on a contour, when I move my mouse on that point.
Second, I anyway get an even distribution of colors, which I cannot control. I created a custom colormap of 8 colors and set up 8 intervals. But the cycle, which modifies data, sets all the values to the maximum, and I miss 1 color anyway. I tried to program it like this:
crange = [0 TS-(TL-TS) TS-0.5*(TL-TS) TS TS+0.25*(TL-TS) TS+0.5*(TL-TS) ...
TS+0.75*(TL-TS) TL max(max(Z))+0.01]';
crange(1:size(crange, 1)-1, 2) = crange(2:size(crange, 1), 1);
crange = crange(1:size(crange, 1)-1,:);
cmap = [0 0 1;
0 0.5 1;
0 1 1;
1 0 0;
1 0.4 0;
1 0.6 0;
1 0.8 0;
1 1 0];
colors = zeros(size(Z));
for c = 1:size(crange, 1)
for i = 1:size(Z, 1)
for j = 1:size(Z, 2)
if Z(i, j) >= crange(c, 1) && Z(i, j) < crange(c, 2)
colors(i, j) = crange(c, 2);
end
end
end
end
contourf(X, Y, colors);
colormap(cmap);
colorbar

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

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by