【问题标题】:Can not apply colormap on a barchart无法在条形图上应用颜色图
【发布时间】:2019-11-28 12:07:04
【问题描述】:

我正在尝试在 matlab 的条形图上应用 colormap。如果您阅读了matlab网页上给出的简短解释,这应该是一件简单的事情,但我仍然无法做到。

b = bar(cell2mat(data_plot'))
set(gca, 'YScale', 'log');
ylabel('Some Label');
xlabel('Some Label')  
colormap (bar, copper)

我没有得到copper 彩色地图,它和以前一样。我也试过以下命令:

colormap copper

仍然没有结果。谁能告诉我,我的错误是什么?

【问题讨论】:

  • 我假设您收到错误,因为您的代码已损坏,对吧?
  • this 是你想要的吗?

标签: matlab plot bar-chart colormap


【解决方案1】:

正确的用法是

colormap copper

但是结果可能不是您所期望的,因为如果您像这样使用颜色图,所有条形图都将具有所选图的第一种颜色。

您可以通过使用循环并单独为条形着色来实现我认为您希望看到的效果:

y = [1 3 5; 3 2 7; 3 4 2];
fHand = figure;
aHand = axes('parent', fHand);
hold(aHand, 'on')
colors = copper(numel(y));
for i = 1:numel(y)
    bar(i, y(i), 'parent', aHand, 'facecolor', colors(i,:));
end

【讨论】:

  • 感谢您的回答。你能解释一下,你到底在用 'parent' 做什么?
  • 这里的方法是,我们创建一个“父”图形fHand 和一个父坐标区aHand,然后将各个条形图作为子级分配给这个父坐标轴,通过指定父级是aHand.
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-07-26
  • 1970-01-01
  • 1970-01-01
  • 2017-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多