boxplot and how to change x-axis

Hi,
I have a matrix (100,7) with data which I want to plot with boxplot. boxplot(matrix) does the job but I haven't figured out yet how I can change the x-axis. Now it draws a box for each column of the matrix. So, the labels go from 1 to 7. I want to replace 1 to 7 with elements provided by another vector (with 7 elements). How can I do that?

回答(3 个)

Use the labels option as described in the docs of boxplot:
X = randn(100,4);
boxplot(X,'Labels',{'one','two','three','four'})
Oleg

2 个评论

All right. Your suggestion works but is a little bit cumbersome.
If the dimensions of X would change I would also have to adapt the labels...
The doc says that I can pass a numeric vector. However, that doesn't work and gives the error
Error using ==> boxplot at 205
Incorrect number of box labels.
even if the number of labels is 7.
Can you show the code that gives you the error?
I don't get any error if I pass a numeric vector of labels, 7, 5 or whatever they are as long as they match the number of columns of my data

请先登录,再进行评论。

Walter Roberson
Walter Roberson 2011-3-3

0 个投票

See the example of a few minutes ago posted by a different user, here
Muhlbauer
Muhlbauer 2011-3-4

0 个投票

It seems there is a bug in boxplot on line 204 in order to support label input from a given input vector.
Adding ~(isvector(labels) && numel(labels)==n) to the if statement beginning on line 202 fixes this issue!

标签

Community Treasure Hunt

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

Start Hunting!

Translated by