How to set log intervals on a logscaled colorbar ?

조회 수: 5 (최근 30일)
Benjamin
Benjamin 2022년 8월 24일
댓글: Dyuman Joshi 2023년 9월 1일
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
Dyuman Joshi
Dyuman Joshi 2023년 9월 1일
Could you please attach your code and data? Use the paperclip button to do so.

댓글을 달려면 로그인하십시오.

답변 (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에서 Purple에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by