フィルターのクリア

How to set log intervals on a logscaled colorbar ?

8 ビュー (過去 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 Center および File ExchangeColormaps についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by