0

I am trying to create a box plot with seaboard as follows:

I have some synthetic data where I have 24 different categories which are generated as:

import numpy as np
x = np.arange(10, 130, step=5)

Now, for each of these categories I generate 5 random observations as follows:

y = np.zeros(shape=(len(y), 5)) # Each row contains 5 observations for a category

Now, what I want to do is do a box plot with seaboard where I plot these 5 values along the y-axes (highlighting the confidence interval) and on the x-axes, I would like each of these categories. So, I do:

import seaborn as sis
fig = sns.boxplot(x=x, y=y)
fig.plt.show()

However, this comes with the exception that the data must be 1-dimensional. I am not sure how to structure my data so that I can plot it.

1 Answer 1

1

The problem, as you point out, is the shape of your input data. Without trying to make too many assumptions as to what you are trying to do, I think you are looking for something like

x = np.arange(10, 130, step=5)
y = 4 * np.random.randn(x.size, 5) + 3

x_for_boxplot = np.repeat(x, 5)
y_for_boxplot = y.flatten()

ax = sns.boxplot(x_for_boxplot, y_for_boxplot)

where x_for_boxplot and y_for_boxplot have been restructured so that they are 1D arrays of the same size which is what sns.boxplot is looking for. I also changed y so that it is made up of random normal values rather than zeros.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.