Set default font
pyfonts.set_default_font(font)
Set the default font for all text elements generated by matplotlib, including axis labels, tick labels, legend entries, titles, etc.
Under the hood it updates all the relevant matplotlib rcParams and
registers the loaded font files with matplotlib. When the font comes
from Google Fonts or Bunny Fonts, pyfonts also attempts to register
the other family variants so later weight= or style= overrides
can be resolved by matplotlib.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
font
|
FontProperties
|
A |
required |
Examples:
```python
from pyfonts import set_default_font, load_google_font
set_default_font(load_google_font("Fascinate Inline"))
plt.title("Title") # will be in Fascinate Inline
plt.plot([1, 2, 3], label="Plot")
# ^ axis labels, ticks, legend entries all also in Fascinate Inline
```
Example
# mkdocs: render
from pyfonts import set_default_font, load_google_font
font = load_google_font("Bitcount")
set_default_font(font) # Sets font for all text
fig, ax = plt.subplots()
ax.plot([0, 1, 2, 3, 4], label='hello')
ax.set_title('Simple Line Chart')
ax.text(x=0, y=3.5, s="Using new default font", size=20)
ax.legend()
font = load_google_font("Roboto")
ax.text(x=0, y=2.5, s="Using a specific font", size=20, font=font)