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

Feature request: groupby.plot() generate subplots not working #12450

Open
RolandRitt opened this issue Feb 26, 2016 · 3 comments
Open

Feature request: groupby.plot() generate subplots not working #12450

RolandRitt opened this issue Feb 26, 2016 · 3 comments

Comments

@RolandRitt
Copy link

I want to make plots of grouped data, where each plot is plotted in a subplot:
I tried without any kwargs in plotting command, i tried with kwargs subplots=True and with layout=(3,1) but always only one plot which includes every group is plotted

My code:

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'].plot(subplots=True) #Figure1
plt.figure()
ax2 = df.groupby('cats')['data'].plot() #Figure2
plt.figure()
ax3 = df.groupby('cats')['data'].plot(layout=(3,1)) #Figure3

Im using

pd.__version__
'0.18.0rc1'
@RolandRitt RolandRitt changed the title groupby.plot() generate subplots not working Feature request: groupby.plot() generate subplots not working Feb 26, 2016
@RolandRitt
Copy link
Author

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

updated 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').plot(subplots=True) #Figure1
plt.figure()
ax2 = df.groupby('cats').plot() #Figure2
plt.figure()
ax3 = df.groupby('cats').plot(layout=(3,1)) #Figure3

@jreback
Copy link
Contributor

jreback commented Feb 26, 2016

@TomAugspurger @sinhrks

@CarloNicolini
Copy link

When having multiple categories, is it possible to reorganize the plot to be in a seaborn FacetGrid format?
Or simply wrapping the columns of the subplot to a certain value?

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

4 participants