gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 20:32:01 25 4
gpt4 key购买 nike

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

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

我没有得到 copper彩色 map ,它是一样的,因为它是。我还尝试了以下命令:

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

Output of bar chart

关于matlab - 无法在条形图上应用颜色图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57113415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com