如何在MATLAB中将茎图覆盖在箱形图上?

时间:2014-03-22 02:43:27

标签: matlab plot

我有一个载体

A=[1 2 3 3 3 4 5]

我可以用

显示其箱形图
boxplot(A, 'orientation', 'horizontal')

我还可以用这样的干线图显示它的分布

[nelements, centers] = hist(A);
stem(centers, nelements/numel(A), 'blue');

我的问题是如何将这两个图组合成一个图?该数字应为y-axis概率,x-axisA值。

关于图中箱形图的高度,没关系。

我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

使用hold on,如下所示,请注意您需要垂直移动(再次使用'position'boxplot以适合stem的轴

boxplot(A, 'orientation', 'horizontal','position',0.1); hold on
[nelements, centers] = hist(A);
stem(centers, nelements/numel(A), 'blue'); hold off

enter image description here

相关问题