Colormap not showing properly
36 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Luis Jesús Olvera Lazcano
le 15 Juin 2023
Commenté : Luis Jesús Olvera Lazcano
le 15 Juin 2023
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.
0 commentaires
Réponse acceptée
DGM
le 15 Juin 2023
Modifié(e) : DGM
le 15 Juin 2023
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 commentaires
DGM
le 15 Juin 2023
Modifié(e) : DGM
le 15 Juin 2023
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)
Plus de réponses (1)
Ishit
le 15 Juin 2023
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.
Voir également
Catégories
En savoir plus sur Colormaps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!