In the following example, I try to make boxplots of "Emission" vs "Voltage" for four "Power" levels, with each power level occupying a subplot.
fig = plt.figure(figsize=(16,9))
i = 0
for 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.suptitle('My Own Title')
The problem is that the
fig.suptitle('My Own Title')
command doesn't flush away the default "Grouped by Voltage" suptitle. What am I missing here? Or is it a bug?
Thanks.
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 = 0
for 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 titles
plt.suptitle('Some title')
You can also do this without manually creating a figure first:
ax = df.boxplot(by=["some_column"])
ax.get_figure().suptitle("")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With