colormap plot adjust colors

19 ビュー (過去 30 日間)
Lieke Numan
Lieke Numan 2019 年 3 月 18 日
編集済み: Adam Danz 2020 年 12 月 7 日
I would like to have a colorbar next to my plot, which runs from green, yellow via orange to red. How can I adjust these colors? I added a figure of an example.
  1 件のコメント
Adam
Adam 2019 年 3 月 18 日
You can use
doc colormapeditor
to do this visually, or create your own colourmap programatically with the key points for green, yellow, orange and red and interpolate between them to produce a colourmap of the desired size.

サインインしてコメントする。

採用された回答

Adam Danz
Adam Danz 2019 年 3 月 18 日
編集済み: Adam Danz 2020 年 12 月 7 日
There are several ways to do this. The colormap jet ranges from blue to green to yellow to red. This solution uses the jet colormap but trims off the bottom half leaving the green-yellow-red but there are a little more shades of red than yellow or green. You could tweek it to fix that.
% Create demo figure
figure
n = 20; %20 data points
Z = peaks(n);
surf(Z);
% Creat colormap from 'jet' with 2x the needed color values
fullCustomMap = jet(n*2);
% Keep the 2nd half of the color range (green to dark red)
customMap = fullCustomMap(n+1:end);
% Define the color map with your custom colors
colormap(customMap)
colorbar
% Scale the colorbar to your data range
caxis([min(Z(:)), max(Z(:))])
Or, you could create your color map from scratch. Here's a demo based on the solution found here: https://www.mathworks.com/matlabcentral/answers/265914-how-to-make-my-own-custom-colormap#answer_207992
n = 20; %number of unique color
base = [0 1 0; 1 1 0; 1 0 0]; %green, yellow, red
customMap = interp1(linspace(n,0,size(base,1)), base, fliplr(0:n), 'pchip')
And here's a website you can use to create a colormap that can be copy-pasted into your matlab code.
  1 件のコメント
Lieke Numan
Lieke Numan 2019 年 3 月 18 日
Thanks a lot!

サインインしてコメントする。

その他の回答 (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