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

标签 matlab plot bar-chart colormap

我正在尝试申请 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/

相关文章:

matlab - 如何绘制由 TrainCascadeObjectDetector 生成的检测器的 ROC 曲线?

r - 在 R 中绘制 Kohonen map 时出错?

reporting-services - SSRS : Custom bar width between multi-level categories

graph - 如何导航 Octave 图?

r - 在 R 中绘制圆圈

python - 在python中分隔条形图组

javascript - 使用 Javascript 从 Json 数据创建图表

matlab - 如何通过for循环在Matlab中读取许多声音文件?

c++ - Eigen C++/Matlab 四元数和旋转矩阵不匹配

matlab - 在 MATLAB 中尝试保持形状时进行形态增厚/扩张