How to set log intervals on a logscaled colorbar ?
13 次查看(过去 30 天)
显示 更早的评论
Hello everyone !
I'm plotting some values on graph (with scatter), and the 'ColorScale' of my colorbar is set to 'log', like this :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1106435/image.png)
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 :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1106440/image.png)
Is there a way to fullfill my desire ?
Thank you in advance !
Ben
1 个评论
Dyuman Joshi
2023-9-1
Could you please attach your code and data? Use the paperclip button to do so.
回答(1 个)
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!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Colormaps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!