matlab 色彩的范围,Matlab - 将2个颜色条设置为带有色彩图和良好范围的2个图例...

我可以绘制下图,实际上,我有2个数据集(一个颜色映射范围为“酷”,另一个颜色映射为“灰色”):我正在单独绘制每个条形图,使每个条形图的颜色取决于它的高度,即它的“y轴”值:

2ab6ee98-77c2-44fc-a040-25a049dba988.png

矩形只是每组条形图的平均值 .

Matlab代码是:

% Plot histograms

figure('Color','w');

title('Bar with height-dependant color');

% Convert y1_full vector to colors

y1_color = vals2colormap(y1_full,'cool');

for k = 1:numel(x1_full)

if (x1_full(k) ~= 0)

bar_h1 = bar(x1_full(k),y1_full(k),'BarWidth',1);

set(bar_h1,'FaceColor',y1_color(k,:));

hold on;

end

end

% Convert y2_full vector to colors

y2_color = 1-0.8*vals2colormap(y2_full,'gray')

for k = 1:numel(x2_full)

if (x2_full(k) ~= 0)

bar_h2 = bar(x2_full(k),y2_full(k),'BarWidth',1);

set(bar_h2,'FaceColor',y2_color(k,:));

hold on;

end

end

% Xlim

xlim([0 max(x2_full)+1]);

现在,我想添加 at the top-right of figure 2 horizontal colorbars ,它代表用于2个数据集('cool'和'gray')中每个数据集的颜色映射,如果可能的话,还添加颜色映射的2个极值 .

这些颜色栏是一种传说,但我不知道如何实现它 .

我尝试过(上面定义了 bar_h1 和 bar_h2 ):

set(bar_h1, 'Location', 'North', 'Position', [0.60 0.70 0.20 0.05]);

set(bar_h2, 'Location', 'North', 'Position', [0.60 0.35 0.20 0.05]);

但我得到这个错误:

Error using matlab.graphics.chart.primitive.Bar/set

There is no Location property on the Bar class.

Error in plot_benchmark_pi_dev (line 89)

set(bar_h1, 'Location', 'North', 'Position', [0.60 0.70 0.20 0.05]);

我也做了:

c1 = colorbar;

c2 = colorbar;

set(c1, 'Location', 'North', 'Position', [0.60 0.70 0.20 0.05]);

set(c2, 'Location', 'North', 'Position', [0.60 0.35 0.20 0.05]);

仍然是一个错误:

Error using matlab.graphics.illustration.ColorBar/set

Invalid or deleted object.

Error in plot_benchmark_pi_dev (line 92)

set(c1, 'Location', 'North', 'Position', [0.60 0.70 0.20 0.05]);

也许我必须直接使用 colormap ,但如何?

如果有人可以帮我绘制这两个水平色图,其范围对应于用于每组条形的范围( cool 和 gray ),这样就可以了 .

ps:用颜色作为高度的函数绘制每个条形图,我使用的是Matlab社区提供的 vals2colormap.m 脚本 .

UPDATE1 :

通过做 :

% Legends

l=legend([bar_h1 bar_h2], 'Data set 1', 'Data set 2');

rect=[0.75, 0.8, 0.1, 0.1];

set(l,'Position',rect,'color','none')

我得到以下结果:

4c9dd522-9104-43db-a791-bcbe23dd221f.png

有没有办法将颜色条放入图例而不是只有一种颜色('cool'为洋红色 Data set 1 和'gray'为 Data set 2 )?

问候

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值