Matlab示例代码无法在Matlab 2017a(Linux 64位)中运行:https://cn.mathworks.com/help/matlab/ref/bar.html https://cn.mathworks.com/help/matlab/ref/bar.html
b = bar(rand(10,1));
b.FaceColor = 'flat';
b.CData(2,:) = [.5 0 .5];
它无法为特定栏着色并发出警告:
matlab.graphics.chart.primitive.Bar 类不存在公共属性 CData。
我不知道这是 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')
如果您想像常规条形图中那样对条形进行编号,可以添加以下内容:
set(gca,'XTick',0.5+[b.XOffset])
set(gca,'XTicklabels',1:length(x))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)