Cannot plot additional scatter points in a boxplot
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello all,
I've got 15 horizontaly orientated boxplots in the same graph with 15 column vectors (x1, x2... x15) each with a different length.
I want to draw two scatter points at y=2 (the points are (x=0.4, y=2.0) and (x=0.6, y=2.0) above the last boxplot which is located at y=1.6.
However I cannot plot those two points and I do know that the command 'hold on' restricts the limits of the boxplots.
*********************************************************************
My code unitl now looks like:
Ypos = [0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.5 1.6];
-----------
group_fordata = [repmat(Ypos(1),[size(x1),1]); repmat(Ypos(2),[size(x2)],1); repmat(Ypos(3),[size(x3)],1); repmat(Ypos(4),[size(x4)],1); repmat(Ypos(5),[size(x5)],1); repmat(Ypos(6),[size(x6)],1); repmat(Ypos(7),[size(x7)],1); repmat(Ypos(8),[size(x8)],1); repmat(Ypos(9),[size(x9)],1); repmat(Ypos(10),[size(x10)],1); repmat(Ypos(11),[size(x11)],1); repmat(Ypos(12),[size(x12)],1); repmat(Ypos(13),[size(x13)],1); repmat(Ypos(14),[size(x14)],1); repmat(Ypos(15),[size(x15)],1)];
-------------
data = [x1;x2;x3;x4;x5;x6;x7;x8;x9;x1;x11;x12;x13;x14;x15]
----------
figure
boxplot(data, group_fordata,'positions', Ypos,'orientation','horizontal')
hold on
plot([0.4 0.6],[2.0 2.0],'g.')
*************************************************************
I cannot see the two points in green plotted. Any alternative to 'hold on' that would allow me to plot something above the value 1.6 of the y-axis?
Many thanks!
댓글 수: 0
채택된 답변
Mike Garrity
2015년 5월 29일
I think it's just that boxplot leaves the YLim in manual mode. Try this:
ylim auto
댓글 수: 3
Mike Garrity
2015년 5월 29일
I don't think that there's a simple shortcut for that, so you're going to need to learn about the Axes object and its properties.
You can get the Axes object using the function "gca". You'll see a bunch of properties on it that you already recognize, such as YLim, but there are lots more:
get(gca)
The one you want is named YTick.
set(gca,'YTick',0:.25:2)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!