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

groupby boxplot creates more subplots than are needed #6769

Closed
fonnesbeck opened this issue Apr 2, 2014 · 5 comments
Closed

groupby boxplot creates more subplots than are needed #6769

fonnesbeck opened this issue Apr 2, 2014 · 5 comments
Labels
Milestone

Comments

@fonnesbeck
Copy link

When calling boxplot on a DataFrameGroupBy object, it does not seem to be able to properly infer the number of subplots required to account for the number of groups. For example, the following:

lsl_dr[lsl_dr.test_type==t].groupby('type').boxplot(column='score', grid=False)

generates this plot:

bad boxplot

Notice that it generates a 2x2 grid, even though there are only three groups. I thought I could deal with this manually by calling pyplot.subplots(1,3), but the boxplot method does not appear to be able to accept an axis argument like the DataFrame.boxplot method does. Is there a work-around for this?

@cpcloud
Copy link
Member

cpcloud commented Apr 2, 2014

Yep you can loop over the groups:

In [66]: df = DataFrame({'cats': np.random.choice(['tabby', 'grumpy', 'smelly'], size=1000), 
                         'weight': normal(13, 5, size=1000)})

In [67]: fig, axs = subplots(1, 3)

In [68]: for (k, v), ax in itertools.izip(df.groupby('cats'), axs.flat):
   ....:     v.boxplot(column='weight', ax=ax)
   ....:

@cpcloud cpcloud added Bug and removed Bug labels Apr 2, 2014
@fonnesbeck
Copy link
Author

That works, thanks. It would be great if DataFrameGroupBy.boxplot were able to take an axis as an argument.

@cpcloud
Copy link
Member

cpcloud commented Apr 2, 2014

What sort of API would you want? Are you thinking axis would take a sequence of axes objects?

@fonnesbeck
Copy link
Author

Yeah, or maybe just rows= or cols=.

@jreback
Copy link
Contributor

jreback commented May 16, 2014

closed by #7035

@jreback jreback closed this as completed May 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants