This should be straightforward: I want to style the matplotlib suptitle
.
Documentation says that fontproperties
is a dict of font properties that can be supplied as a parameter.
So:
import matplotlib.pyplot as plt
import matplotlib as mpl
fig, ax = plt.subplots()
ax.set_xlim(0, 1)
fdct = {'color': 'r', 'fontsize': 32}
# Generates error
fig.suptitle('A title', fontproperties=fdct)
# Works
fig.suptitle('A title', fontsize=32)
The first command generates
TypeError: FontProperties.__init__() got an unexpected keyword argument 'color'
But why? I would like to style suptitle with a dict of font properties, like I do for other instances of Text
.
2
color
is not a property of a font, it is a property of a Text
(which, besides color
, has a fontproperties
property that is populated by suptitle
with a FontProperties
instance given its fontproperties
dictionary argument).
suptitle
returns the Text
instance that it creates. You can change its color
property either by using its set
method with the color
keyword argument, or more explicitly by its set_color
method.