我有一个一维数组 X,其中包含相关系数的统计数据,我想绘制一个彩色直方图。我使用以下代码:
histogram(X,10)
它可以创建具有单色的直方图,现在我想绘制一个直方图,其中每个条形都有不同的颜色。但“FaceColor”选项只能调整整个绘图的总颜色。谁能告诉我如何实现这一目标?
你没有这样的控制能力histogram
对象,而不是你必须使用bar
绘图,其中每个条形的高度最好用以下公式计算histcounts
.
[h,edges] = histcounts(x,10); % calculate the histogram data
b = bar( (edges(1:end-1)+edges(2:end))/2, h ); % plot the bar chart
b.BarWidth = 1; % make the bars full width to look the same as 'histogram'
b.CData = parula( 10 ); % generate colours as a 10x3 array (columns are RGB), can
% do this manually if you want
b.FaceColor = 'flat'; % Make 'bar' use the CData colours
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)