Set no title for pandas boxplot (groupby)

27,951

Solution 1

Make sure your calling suptitle('') on the right figure.

In [23]: axes = df.boxplot(by='g')

In [24]: fig = axes[0][0].get_figure()

In [25]: fig.suptitle('')
Out[25]: <matplotlib.text.Text at 0x109496090>

Solution 2

I had the same problem. Ended up using this solution

import matplotlib.pyplot as plt    
# df is your dataframe
df.boxplot(column='value', by='category')
title_boxplot = 'awesome title'
plt.title( title_boxplot )
plt.suptitle('') # that's what you're after
plt.show()

Solution 3

I as having problems with this and generally never liked the canned title that the pandas was adding as it was dependent on the column names which are typically never publishing ready.

You can edit the source code in ~\pandas\plotting\_core.py

On line 2698 you will find:

fig.suptitle('Boxplot grouped by {byline}'.format(byline=byline))

Simple comment this line out and pandas will no longer add the title to the top of the boxplot by default. You will have to redo this change as you upgrade pandas versions.

Solution 4

None of the above solutions worked for me, but this one did:

axes = df.boxplot(column=values, by=index, ax=ax, rot=90)
axes.set_title('')

Solution 5

After trying all the suggestions, only this modification worked for me, which also lets you modify other parameters:

ax = df.boxplot(by ='value', column =['category'], grid = False);
plt.title('')
plt.suptitle('')
ax.set_title('');
ax.set_xlabel("x_label");
ax.set_ylabel("y_label");
ax = plt.show()
Share:
27,951
user308827
Author by

user308827

Updated on February 17, 2022

Comments

  • user308827
    user308827 over 2 years

    When drawing a pandas boxplot, grouped by another column, pandas automatically adds a title to the plot, saying 'Boxplot grouped by....'. Is there a way to remove that? I tried using

    suptitle('')
    

    as per Pandas: boxplot of one column based on another column

    but this does not seem to work. I am using latest pandas (0.13.1) version.