Skip to content

Feature request: groupby.hist() plot each hist in a subplot #12451

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
RolandRitt opened this issue Feb 26, 2016 · 2 comments
Closed

Feature request: groupby.hist() plot each hist in a subplot #12451

RolandRitt opened this issue Feb 26, 2016 · 2 comments

Comments

@RolandRitt
Copy link

I'd like to use the kwarg subplots=True when plotting histogramms of groupby
My code:

import os
import sys
import datetime
import matplotlib.pyplot as plt
import pandas as pd
import matplotlib.dates as mdates
import numpy as np


%matplotlib notebook


dates = pd.date_range('2013-07-14 11:00:00', '2013-07-16 11:00:00', freq = 's')
cats = np.random.choice(['m', 'f', 'c'], len(dates))
data =np.random.randn(len(dates),1)

df = pd.DataFrame(data, dates)
df.columns = ['data']
df['cats']= cats

plt.figure()
ax1 = df.groupby('cats')['data'].hist(bins=20, normed=True, subplots=True) #Figure --> not working with subplots=True

Would be nice to have this feature in pandas (same would be nice to have in groupby.plot #12450 )

My pandas:

pd.__version__
'0.18.0rc1'
@RolandRitt
Copy link
Author

I just found out that if i change ax1 = df.groupby('cats')['data'].hist(bins=20, normed=True, subplots=True) to ax1 = df.groupby('cats').hist(bins=20, normed=True, subplots=True) seperate plots are generated, but it woult be nice here to define, that each group is plotted as a subplot..(or as a row of a subplot)

updated Code:

mport os
import sys
import datetime
import matplotlib.pyplot as plt
import pandas as pd
import matplotlib.dates as mdates
import numpy as np


%matplotlib notebook


dates = pd.date_range('2013-07-14 11:00:00', '2013-07-16 11:00:00', freq = 's')
cats = np.random.choice(['m', 'f', 'c'], len(dates))
data =np.random.randn(len(dates),1)
data2 =np.random.randn(len(dates),1)

df = pd.DataFrame(data, dates)
df.columns = ['data']
df['cats']= cats
df['data2'] = data2

plt.figure()
ax1 = df.groupby('cats').hist(bins=20, normed=True) #Figure1

@jreback
Copy link
Contributor

jreback commented Feb 26, 2016

covered by #8018

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

No branches or pull requests

2 participants