无法在条形图上应用颜色图

Can not apply colormap on a barchart

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

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

我没有得到 copper 色图,它和原来一样。我还尝试了以下命令:

colormap copper

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

正确的用法是

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