필터 지우기
필터 지우기

Vertical boxplot?

조회 수: 13 (최근 30일)
Muhlbauer
Muhlbauer 2012년 1월 11일
Hi,
I have a data matrix A(15,1000) for which I would like to plot the statistics of the date contained in each of the 15 rows in a Box-Whisker style plot. That is easily accomplished with boxplot. However, I was unable to make the boxes line up in the direction of the y-axis instead of the x-axis. Basically, I would like to have a vertical box plot, where the y-axis would go from y(1) to y(15).
How can I do this?

답변 (2개)

Walter Roberson
Walter Roberson 2012년 1월 11일
"boxplot(X) produces a box plot of the data in X. If X is a matrix, there is one box per column; "
Since you want one box per row instead of per column, you need to transpose the data you sent to boxplot
boxplot(A.', 'orientation', 'horizontal');
  댓글 수: 2
Andreas
Andreas 2012년 1월 12일
Thanks, Walter. That at least plots the boxes vertically as I want it. However, the positions at which the boxes are drawn still go from 1 to 15 and not y(1) to y(15). I basically want to create the boxes first and then add another line plot that shows some other data and how it compares to the boxes. So, what I want is the following:
x = 1:1:15; y = f(x);
figure; boxplot(X','orientation','horizontal'); hold on; plot(x,y);
Walter Roberson
Walter Roberson 2012년 1월 12일
It is better to get in the habit of using .' instead of ' as otherwise you are going to have a hard time figuring out why you are having problems working with complex values.
Anyhow, like this:
figure;
h = boxplot(A.', 'orientation', 'horizontal');
for K = 1 : length(h)
set(h(K), 'YData', f(get(h(K),'YData')));
end
hold on
plot(f(1:size(A,1)));
Note that A must not be a vector: vectors always produce a single box, no matter what the orientation of the vector.

댓글을 달려면 로그인하십시오.


Tom Lane
Tom Lane 2012년 1월 13일
Could it be that you want to use the 'positions' argument?
rowvals = [1 2 4 8]';
x = bsxfun(@plus,rowvals,randn(4,20));
boxplot(x','ori','horizontal','positions',rowvals)
Then maybe get rid of the group numbers:
set(gca,'ytickmode','auto')
set(gca,'yticklabelmode','auto')

태그

Community Treasure Hunt

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

Start Hunting!

Translated by