How to flush away the default suptitle of boxplot with subplots made by pandas package for python
Those are generated by suptitle()
calls, and the super titles are the children of fig
object (and yes, the suptitle()
were called 4 times, one from each subplot).
To fix it:
df = pd.DataFrame({'Emission': np.random.random(12), 'Voltage': np.random.random(12), 'Power': np.repeat([10,20,40,60],3)})fig = plt.figure(figsize=(16,9))i = 0for Power in [10, 20, 40, 60]: i = i+1 ax = fig.add_subplot(2,2,i) subdf = df[df.Power==Power] bp = subdf.boxplot(column='Emission', by='Voltage', ax=ax)fig.texts = [] #flush the old super titlesplt.suptitle('Some title')
You can also do this without manually creating a figure first:
ax = df.boxplot(by=["some_column"])ax.get_figure().suptitle("")
Until someone can give a better answer, here is a hack, assuming the new title is longer than the old one.
fig.suptitle('My Own Title',backgroundcolor='white', color='black')
It basically hides the old title, instead of flushing it.