Skip to content

Issue with Pandas boxplot within a subplot #3578

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

Closed
ghl3 opened this issue May 11, 2013 · 3 comments
Closed

Issue with Pandas boxplot within a subplot #3578

ghl3 opened this issue May 11, 2013 · 3 comments
Labels
Milestone

Comments

@ghl3
Copy link

ghl3 commented May 11, 2013

related is #4636

I'm having an issue drawing a Pandas boxplot within a subplot. Based on the two ways I'm trying, creating the boxplot either removes all the subplots that I've already created, or plots the boxplot after the subplot grid. But I can't seem to draw it within the subplot grid.

import matplotlib.pyplot as plt
import pandas
from pandas import DataFrame, Series

data = {'day' : Series([1, 1, 1, 2, 2, 2, 3, 3, 3]), 
        'val' : Series([3, 4, 5, 6, 7, 8, 9, 10, 11])}
df = pandas.DataFrame(data)

The first thing I've tried is the following:

plt.figure()

plt.subplot(2, 2, 1)
plt.plot([1, 2, 3])

plt.subplot(2, 2, 4)
df.boxplot('val', 'day')

But this simply creates the plot outside of the subplots:

image
image

So, I then tried supplying the axis by hand:

plt.figure()

plt.subplot(2, 2, 1)
plt.plot([1, 2, 3])

plt.subplot(2, 2, 4)
ax = plt.gca()
df.boxplot('val', 'day', ax=ax)

image

It seems that an internal call to subplot is messing up my desired subplot structure, preventing me from getting my boxplot image to appear in the bottom right grid in the subplots (the one that's empty in the first set of images)?

See this question on StackOverflow:
http://stackoverflow.com/questions/16500079/issue-with-pandas-boxplot-within-a-subplot

@jreback
Copy link
Contributor

jreback commented Sep 22, 2013

@cpcloud can you have a look if you have a chance

@ghost ghost assigned cpcloud Sep 22, 2013
@cpcloud
Copy link
Member

cpcloud commented Jan 29, 2014

man that SO answer is basically a PR!

@jreback jreback modified the milestones: 0.15.0, 0.14.0 Mar 28, 2014
@jreback jreback modified the milestones: 0.14.1, 0.15.0 May 6, 2014
@jreback jreback modified the milestones: 0.14.0, 0.14.1 May 6, 2014
onesandzeroes added a commit to onesandzeroes/pandas that referenced this issue May 8, 2014
axes needs to be a plt.Axes object

use ax get_axes() to set axes

Add tests for use of existing axis

Add test for when by is None

Add fix to the release notes
TomAugspurger pushed a commit that referenced this issue May 8, 2014
axes needs to be a plt.Axes object

use ax get_axes() to set axes

Add tests for use of existing axis

Add test for when by is None

Add fix to the release notes
@jreback
Copy link
Contributor

jreback commented May 8, 2014

closed by #6991

@jreback jreback closed this as completed May 8, 2014
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

3 participants