Using a color scale on a plot
72 ビュー (過去 30 日間)
古いコメントを表示
I have made an experiment and want to show the results. I want to add a color scale so the function with the value "-10.4" is blue and the value "1.3" is yellow and the others some color in between. It could also be another color or the whole color scheme. Additionality i want a color scale that shows the relationship between the colors and the values. How do i do that?
figure(1)
plot(X1,abs1)
hold on
plot(X2,abs2)
hold on
plot(X3,abs3)
hold on
plot(X4,abs4)
hold on
plot(X5,abs5)
legend("-10.4","-6","-2.3","0.3","1.3")
0 件のコメント
回答 (1 件)
Voss
2022 年 10 月 26 日
f = figure();
% use colormap parula because it goes blue -> yellow:
cmap = parula();
% define the color limits:
clim = [-10.4, 1.3];
% define the values to use for line colors:
vals = [-10.4, -6, -2.3, 0.3, 1.3];
% indices into cmap of vals, using clim as the upper and lower limits:
idx = 1+round((vals-clim(1))/(clim(2)-clim(1))*(size(cmap,1)-1));
% colors from colormap at those indices:
line_colors = cmap(idx,:);
% plot (random) lines with those colors:
hold on
for ii = 1:numel(vals)
plot(0:0.5:4.5,rand(1,10),'Color',line_colors(ii,:),'LineWidth',1.5);
end
% create the legend:
legend("-10.4","-6","-2.3","0.3","1.3")
% create the colorbar:
set(f,'Colormap',cmap);
caxis(clim)
colorbar();
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!