Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add title to collection of pandas hist plots

I'm looking for advice on how to show a title at the top of a collection of histogram plots that have been generated by a pandas df.hist() command. For instance, in the histogram figure block generated by the code below I'd like to place a general title (e.g. 'My collection of histogram plots') at the top of the figure:

data = DataFrame(np.random.randn(500).reshape(100,5), columns=list('abcde')) axes = data.hist(sharey=True, sharex=True) 

I've tried using the title keyword in the hist command (i.e. title='My collection of histogram plots'), but that didn't work.

The following code does work (in an ipython notebook) by adding text to one of the axes, but is a bit of a kludge.

axes[0,1].text(0.5, 1.4,'My collection of histogram plots', horizontalalignment='center',                verticalalignment='center', transform=axes[0,1].transAxes) 

Is there a better way?

like image 801
dreme Avatar asked Oct 27 '13 03:10

dreme


People also ask

How do I add a label to a plot in pandas?

You can set the labels on that object. Or, more succinctly: ax. set(xlabel="x label", ylabel="y label") . Alternatively, the index x-axis label is automatically set to the Index name, if it has one.

How do I add a title to my Seaborn plot?

To add a title to a single seaborn plot, you can use the . set() function. To add an overall title to a seaborn facet plot, you can use the . suptitle() function.


1 Answers

With newer Pandas versions, if someone is interested, here a slightly different solution with Pandas only:

ax = data.plot(kind='hist',subplots=True,sharex=True,sharey=True,title='My title') 
like image 66
Filippo Mazza Avatar answered Sep 29 '22 00:09

Filippo Mazza