Skip to content Skip to sidebar Skip to footer

Set No Title For Pandas Boxplot (groupby)

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 usi

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()

Post a Comment for "Set No Title For Pandas Boxplot (groupby)"