フィルターのクリア

How to fix a limit between 2 combined colormaps?

25 ビュー (過去 30 日間)
Leandra
Leandra 2024 年 7 月 3 日 15:10
編集済み: DGM 2024 年 7 月 3 日 17:56
My problems is that I'm trying to use two combined colorbars to get more color range in depicting my values. But if I define clim ([100 350]) w the average gets used as the splitting point between the 2 colormaps (meaning here 225). Now, I know that I can fix the colorbar manually by shifting it in the figures and saving it then, but this is very impractical since I'm trying to create many figures. Is there any good line of code, that could help me fix the limit directly?
My code:
clim([100 350])
colormap([flipud(m_colmap('blues')); colormap(slanCM(6))])
I would like to use the "blues'" colormap for values between 100 and 200, the other one for values between 200 and 350.
Any help would be greatly appreciated.

採用された回答

DGM
DGM 2024 年 7 月 3 日 17:38
編集済み: DGM 2024 年 7 月 3 日 17:56
Get out of the habit of generating colormaps without specified lengths. If you use implicit lengths, you can easily wind up with the map lengths varying uncontrollably every time you run your code unless the figure is deleted (not just cleared).
You have two unequal intervals, so your two map segments need to have different lengths. You can either do that by generating them at that length.
% some fake data
x = 50:175;
Z = x + x.';
% plot it somehow
imagesc(Z)
% colormap breakpoints and lengths
breakpts = [100 200 350];
l1 = 256; % pick something
l2 = round(l1*(breakpts(3) - breakpts(2))/(breakpts(2) - breakpts(1)));
% generate and apply the colormaps
CT1 = m_colmap('blues',l1);
CT2 = slanCM('parula',l2);
colormap([flipud(CT1); CT2])
% set the colorbar/clim
clim(breakpts([1 end]))
colorbar
Alternatively, if you want the slopes of the two maps to be the same, you can generate the two maps to have the same length, and then trim the shorter map to length. Note now that 'blues' doesn't run all the way to white anymore.
% some fake data
x = 50:175;
Z = x + x.';
% plot it somehow
imagesc(Z)
% colormap breakpoints and lengths
breakpts = [100 200 350];
l0 = 512; % the length of the longer map segment
l1 = round(l0*(breakpts(2) - breakpts(1))/(breakpts(3) - breakpts(2)))
% generate and apply the colormaps
CT1 = m_colmap('blues',l0);
CT1 = CT1(1:l1,:); % trim the shorter map segment
CT2 = slanCM('parula',l0);
colormap([flipud(CT1); CT2])
% set the colorbar/clim
clim(breakpts([1 end]))
colorbar

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by