Matlab: bar 不存在公共(public)属性 CData

标签 matlab colors matlab-figure

Matlab 示例代码无法在 Matlab 2017a(Linux 64 位)中运行: https://cn.mathworks.com/help/matlab/ref/bar.html

b = bar(rand(10,1));
b.FaceColor = 'flat';
b.CData(2,:) = [.5 0 .5];

它无法为特定栏着色并发出警告:

No public property CData exists for class matlab.graphics.chart.primitive.Bar.

我不知道这是 Matlab 2017b 的特定功能吗?

此代码仅用于为特定条形图着色。在 Matlab 2012a 中,可以通过以下方式轻松完成:

bh=bar(MyStem); h=get(bh, 'children');
shading flat;  set(h,'FaceVertexCData',MyColor);

我无法理解为什么 Matlab 2017 会删除此功能。

最佳答案

关于 CData 属性,我已经在评论中写了。 无论如何,我认为可以比建议的更简单的另一种解决方法是:

x=rand(1,10);
b=bar([x;zeros(1,length(x))]);
xlim([0.5 1.5])
set(b,'FaceColor','r')
set(b(2),'FaceColor','b')

enter image description here

如果你想像在常规条形图中一样对条形进行编号,你可以添加:

set(gca,'XTick',0.5+[b.XOffset])
set(gca,'XTicklabels',1:length(x))

enter image description here

关于Matlab: bar 不存在公共(public)属性 CData,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47281603/

相关文章:

sqlite - 有什么办法可以让 SQLite 输出彩色吗?

r - 转换颜色以模仿灰度打印

具有意外翻转的 Matlab 图像和绘图

MATLAB R2014b : Rendering plots with lines in the same place

python - 计算相机内在参数时获取复数

MATLAB 在 Linux 上内存不足,尽管经常出现 "clear all"

android - Xamarin:进度条改变颜色

matlab - Matlab 中 'end' 的语义是什么?

string - MATLAB:如何从单元格数组 B 中删除单元格数组 A 的元素?

MATLAB 子图导出