Azzera filtri
Azzera filtri

Vertical boxplot?

10 visualizzazioni (ultimi 30 giorni)
Muhlbauer
Muhlbauer il 11 Gen 2012
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?

Risposte (2)

Walter Roberson
Walter Roberson il 11 Gen 2012
"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 Commenti
Andreas
Andreas il 12 Gen 2012
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 il 12 Gen 2012
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.

Accedi per commentare.


Tom Lane
Tom Lane il 13 Gen 2012
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')

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by