Hold on command does not work for boxplot and additional plot
3 views (last 30 days)
Show older comments
Hello all,
I've got a boxplot (with horizontal orientation) with data:
a= [x1;x2;x3;x4;x5;x6;x7;x8;x9;x10;x11;x12;x13;x14;x15]
and the boxplot groups are defined by vector b, where b is:
b = [0*ones(size(x1)); 0.1*ones(size(x2)); 0.2*ones(size(x3)); 0.3*ones(size(x4)); 0.4*ones(size(x5)); 0.5*ones(size(x6)); 0.6*ones(size(x7)); 0.7*ones(size(x8)); 0.8*ones(size(x9)); 0.9*ones(size(x10)); 1.0*ones(size(x11)); 1.1*ones(size(x12)); 1.2*ones(size(x13)); 1.5*ones(size(x14)); 1.6*ones(size(x15))];
where, the positions 0, 0.1, 0.2, 0.3, 0.4......., 1.6 are the positions that my horizontal boxplots are taking on the y axis.
----------
I want to overlap a plot with 5 points say c=[0.3, 0.4, 0.5, 0.6, 0.7] at y=2.
------------
So, when I'm typing
figure
boxplot(a,b,'orientation','horizontal')
hold on
plot(c,2*ones(size(c)),'g.')
it does not work and only the boxplots are shown, but not my 5 points (that are above the highest y value of the boxplots, which is 1.6).
Any ideas of how I could resolve this?
0 Comments
Answers (1)
Walter Roberson
on 25 May 2015
"hold on" affects the xlim and ylim.
3 Comments
Walter Roberson
on 25 May 2015
Edited: Walter Roberson
on 25 May 2015
I do not have the Stats toolbox so I cannot test this.
You are passing in your b in G, the grouping variables. Grouping variables designate only groupings, not positions. And I think you are passing in the wrong size of grouping variables unless your x* values are all column vectors.
I think what you are wanting is the 'positions' option:
Box positions specified as a numeric vector with one entry per group or X value. The default is 1:numGroups, where numGroups is the number of groups.
Your grouping variable might as well be integer valued,
[1 * ones(size(x1,1),1); 2 * ones(size(x2,1),1); ... ]
and then your 'positions' would be 0:.1:1.6
and then you would be able to meaningfully plot at y=2 and not have it show up near the bottom of your plot.
I suggest, by the way, that instead of using
hold on
that you use line() to draw the line instead of using plot() to draw it. line() is a graphics primitive object that does not erase anything.
See Also
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!