How to set log intervals on a logscaled colorbar ?

8 次查看(过去 30 天)
Hello everyone !
I'm plotting some values on graph (with scatter), and the 'ColorScale' of my colorbar is set to 'log', like this :
I want to reduce the number of 'colors' of the colormap jet to better segment my data.
Ideally I want to segment according to log ticks of the colorbar, but I only achieve to get a linear segmentation on a log colorbar :
Is there a way to fullfill my desire ?
Thank you in advance !
Ben

回答(1 个)

Nivedita
Nivedita 2023-9-1
Hi Benjamin!
I understand that you are trying to achieve the segmentation of your colorbar according to logscale and have the log ticks appear at the segments.
I have tried to implement the above requirement using random data in the following piece of code:
% Set the colormap and its logarithmic segmentation
cmap = jet(5); % Choose any colormap you prefer and specify the number of segments
numTicks = 6; % Number of colorbar ticks
c = colorbar;
c.Ticks = [1 10 100 1000 10000 100000];
c.TickLabels = cellstr(num2str(c.Ticks'));
colormap(cmap);
clim([1, 100000]);
set(gca, 'ColorScale','log');
  • You can determine the custom colormap that you wish to use in your colorbar. The various colormap options available can be found in the documentation link here: Colormap Name.
  • In the example provided I have used the colormap named “jet” and specified the number of segments that I require in the following brackets.
  • I have then set the number of tick values to 6 (for 5 segments), specified the tick values and the tick labels. For more details on Colorbar properties, you can refer to the documentation here: Colorbar appearance and behavior - MATLAB
  • I have set the colormap limits using the “clim” function and finally in the last line, set the “ColorScale” to “log” as mentioned.
I hope it helps!

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by