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() and groupby.hist() add groupname as figure title #12452

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

Comments

@RolandRitt
Copy link

Hello!
I'm plotting histogramms and line plots from a groupby - object. It works fine and for each group a figure is generated. But i think a nice feature would be to automatically add the groupname (label) as figure title to each figure. Below you can see a line and a histplot from one group

groupby_plot
groupby_hist

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

Pandas:

pd.__version__
'0.18.0rc1'

@jreback
Copy link
Contributor

jreback commented Feb 26, 2016

xref to #6279

@jreback
Copy link
Contributor

jreback commented Feb 26, 2016

@TomAugspurger @sinhrks

@VolkerH
Copy link

VolkerH commented Dec 7, 2018

I was looking for this functionality and a google search has brought me to an open issue rather than to a solution on stackoverflow :-)
Is there a solution that I'm missing?

@vetakim
Copy link

vetakim commented Mar 1, 2024

I was looking for this functionality and a google search has brought me to an open issue rather than to a solution on stackoverflow :-) Is there a solution that I'm missing?

I've found a way to add title like this:

my_group = my_data_frame.groupby("name")
my_axes_data_frame = my_group.plot("x", "y")
for index in my_axes_data_frame.index:
    my_axes_data_frame.loc[index].set_title(index)
plt.show()

This works for me with my pandas version 0.23.3.

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

5 participants