How to change the colorbar limits in Matlab?
142 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hylke Dijkstra
el 22 de En. de 2023
Comentada: Hylke Dijkstra
el 25 de En. de 2023
Dear all,
I want to apply log scaling to my colormap because the data I have is heavily skewed. My code is the following:
A = rand(1435);
h = heatmap(A, 'Colormap',flip(hot),'ColorScaling','log','ColorLimits',[10^-5 10^0], 'ColorMethod','none');
XLabels = 1:1435;
YLabels = 1:1435;
% Convert each number in the array into a string
CustomXLabels = string(XLabels);
CustomYLabels = string(YLabels);
% Replace all but the fifth elements by spaces
CustomXLabels(mod(XLabels,1436) ~= 0) = " ";
CustomYLabels(mod(YLabels,1436) ~= 0) = " ";
% Set the 'XDisplayLabels' property of the heatmap
% object 'h' to the custom x-axis tick labels
h.XDisplayLabels = CustomXLabels;
h.YDisplayLabels = CustomYLabels;
clim([10^-5 10^0]);
grid off
Note that my A matrix is in my case different, but for this example I do not have to share my data. The problem that I have is that the colorbar for this heatmap ranges from a little below 1.2 to slightly above 2.6. Since all my numbers are between 0 and 1 this is not what I want. I want log scaling between the numers 10^-5 and 10^0. I tried to use ColorLimits and clim but it does not seem to do the trick..
Any help would be appreciated!
Best
0 comentarios
Respuesta aceptada
Walter Roberson
el 22 de En. de 2023
'ColorScaling','log','ColorLimits',[10^-5 10^0]
When you specify colorscaling log, the colorlimits are the logs of the limits -- so you ended up with exp(1e-5) to exp(1) as your limits.
Más respuestas (1)
Sulaymon Eshkabilov
el 22 de En. de 2023
clim does the job, e.g.:
surf(peaks)
clim([1.2 2.6])
colorbar
0 comentarios
Ver también
Categorías
Más información sobre Data Distribution Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!