Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting the order of boxes in sns.boxplot() #14

Closed
waltonjones opened this issue Nov 21, 2013 · 7 comments
Closed

Setting the order of boxes in sns.boxplot() #14

waltonjones opened this issue Nov 21, 2013 · 7 comments
Labels

Comments

@waltonjones
Copy link

Love what you are doing with this visualization library.

I am having a hard time, though, figuring out how to set the order for a groupby boxplot. The order of the boxes seems to follow the sorted order of the groupby functionality, alphabetical when I am grouping by genotype. Labels on the boxes, however, seem to follow the order the data take in the dataframe. This leads to mislabeled plots.

Is there a way to specify the order in which the boxes appear?

@mwaskom
Copy link
Owner

mwaskom commented Nov 21, 2013

Uh oh, that sounds like a bug. Let me look into it.

@waltonjones
Copy link
Author

If you need sample data to replicate, please let me know. I am happy to
provide an IPython notebook and the data file, but I would rather not
put it up on Github just yet. :)

On 21 Nov 2013, at 12:08, Michael Waskom wrote:

Uh oh, that sounds like a bug. Let me look into it.


Reply to this email directly or view it on GitHub:
#14 (comment)

@mwaskom
Copy link
Owner

mwaskom commented Nov 21, 2013

Indeed, it looks like the boxes end up in the alphabetical order of the grouping variable, but the xlabel names end up in the order they appear in the Series. I have replicated it in this gist.

For the time being, you can specify the names as a parameter (demonstrated in the final cell of the example notebook).

Thanks for reporting this! I'll open a PR to fix it tonight.

@waltonjones
Copy link
Author

You are fast, my friend. Like lightning.

On 21 Nov 2013, at 12:19, Michael Waskom wrote:

Indeed, it looks like the boxes end up in the alphabetical order of
the grouping variable, but the xlabel names end up in the order they
appear in the Series. I have replicated it in this
gist
.

For the time being, you can specify the names as a parameter
(demonstrated in the final cell of the example notebook).

Thanks for reporting this! I'll open a PR to fix it tonight.


Reply to this email directly or view it on GitHub:
#14 (comment)

@mwaskom
Copy link
Owner

mwaskom commented Nov 21, 2013

Fixed in master!

@waltonjones
Copy link
Author

Shall I put in another feature request for the ability to easily specify the order of the boxplot?

@mwaskom
Copy link
Owner

mwaskom commented Nov 21, 2013

Sure, go ahead and open a separate issue for that. This fix reminded me that there is a lot of gross repeated code in the setup for boxplot and violin that should be abstracted out. I probably will add the ordering when I get to that, otherwise it will just add more messiness.

In the meantime, you could do (extending the gist example):

cols = ["b", "c", "a"]
data = df.x.groupby(df.g).values[cols]
sns.boxplot(data, names=cols)

as a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants