フィルターのクリア

Colormap not showing properly

36 ビュー (過去 30 日間)
Luis Jesús Olvera Lazcano
Luis Jesús Olvera Lazcano 2023 年 6 月 15 日
I used both cmocean and colormap for plots, and when I dont define the levels of the color (i.e. the quantity of colors) it displays normally. But when I put the quantity such as:
colormap(jet(15))
cmocean('tarn',15) (this is in the climate data toolbox
The higher colors are distorted as I show you here (the distorted vs the normal colormap)
Whats the reason? I checked both 2023a and 2022b versions and the problem is still here.

採用された回答

DGM
DGM 2023 年 6 月 15 日
編集済み: DGM 2023 年 6 月 15 日
This looks exactly like what should be expected. When you quantize your z data to 15 levels, you have less z-resolution than when you quantize your data to (e.g.) 256 levels.
x = linspace(0,1,50);
y = linspace(0,1,50).';
z = x+y;
imagesc(z)
colorbar
colormap(jet) % default is 256 in newer versions
figure
imagesc(z)
colorbar
colormap(jet(16)) % explicitly use fewer levels
It should be noted that when you don't specify the number of levels, the number of levels that's used depends on the version that you're running (defaults are either 64 or 256) and the last colormap that was used in the same figure (even if the figure has been explicitly cleared). If you care about the number of levels in the colormap, you must specify it explicitly.
% if the length of the colormap is unspecified, and we have an existing
% figure open, the length of the new colormap will be the same as the
% length of the last colormap used in that figure
clf % clear the figure
imagesc(z)
colorbar
colormap(parula) % default is ignored, and the length of the last map is used
% so explicitly specify the map length if you want a particular length
clf % clear the figure
imagesc(z)
colorbar
colormap(parula(256)) % explicitly specify the desired map length
This behavior is mentioned in the documentation for jet(), parula(), etc.
  3 件のコメント
DGM
DGM 2023 年 6 月 15 日
編集済み: DGM 2023 年 6 月 15 日
I added more examples and code comments. If you're seeing the relative positions of colored regions shift when you rerun the code, that may be due to the length of the colormap changing (if it's not specified), or that may also be due to the color axis limits changing. See clim() (or caxis() in older versions)
Luis Jesús Olvera Lazcano
Luis Jesús Olvera Lazcano 2023 年 6 月 15 日
Thanks for the examples! Unfortunately it kept happening, even specifying more in the clim().
But I noted one thing, I downloaded the 2021b version in my pc, and it works perfectly fine, the colors dont get distorted. Do you know why in more recent versions the "levels" doesnt work properly?

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

その他の回答 (1 件)

Ishit
Ishit 2023 年 6 月 15 日
Hi Luis,
The reason for the distortion in the higher colors of your colormap when you define the number of levels is likely due to the way that the colors are mapped to the data values. When you specify the number of levels (i.e., the number of colors) in your colormap, MATLAB or the Climate Data Toolbox (CDT) uses that number to determine how to map the colors to the data values.
It's also possible that there may be differences in the way that colormap and cmocean handle the mapping of colors to data values. You may want to try using different colormaps or adjusting the parameters of the colormap functions to see if that resolves the issue.
  1 件のコメント
Luis Jesús Olvera Lazcano
Luis Jesús Olvera Lazcano 2023 年 6 月 15 日
Hello! Thank you for your response
I have tried to put other colormaps (jet, parula, etc) and it does the same thing. The thing is that, when I try several times, SOMETIMES it does it normal, but most of the times it does not. Its more probable to happen if I specify lower number of levels (30,20,10..)

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

カテゴリ

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

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by