Creating plot over the Box plot

4 次查看(过去 30 天)
Hi Friends,
A = 4; B = 6; C = 8; D = 9;
values = [A;B;C;D]
Y = [500];
labels = {'a','b','c','d','e'}
figure
hold on
boxplot(values,Y);
plot(Y,values,'r*')
I'm trying to use hold on to view plot (*) on the boxplot. But, it doesn't work well and I only see box plot not the plot over it.
Thanks

采纳的回答

Jeffrey Eymer
Jeffrey Eymer 2018-6-19
You are misunderstanding how the arguments to boxplot are used. boxplot(values, [500]) does not actually move the box plot to the x-value of 500, rather it just labels the box plot with an x-value of 500. The box plot itself still resides at x=1.
To accomplish what you are trying to do, replace the line with
boxplot(values, Y, 'positions', Y);
The 'positions' argument designates where the box plot will actually be placed on the graph.
  2 个评论
Minha Ferouz
Minha Ferouz 2018-6-20
Thanks Jeffrey. It worked. I also find another way to set x-axis using
hAx = gca;
xtk=hAx.XTick;
hold on
hl = plot(xtk,A,'r*')
Could you also tell me how I can set 'labels' against each data point on boxplot?
Minha Ferouz
Minha Ferouz 2018-6-20
编辑:Minha Ferouz 2018-6-20
for t = 1:5
text(Y,A(t),labels(t))
end
Used this and it seems to be working fine. The only problem I have now is that the labels are not readable and appear over the data points.

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by