Load Google font
pyfonts.load_google_font(family, weight=None, italic=None, allowed_formats=['woff2', 'woff', 'ttf', 'otf'], use_cache=True, danger_not_verify_ssl=False)
Load a font from Google Fonts with specified styling options and return a font property object that you can then use in your matplotlib charts.
The easiest way to find the font you want is to browse Google font
and then pass the font name to the family argument.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
family
|
str
|
Font family name (e.g., "Open Sans", "Roboto", etc).
weight: Desired font weight (e.g., 400, 700) or one of 'thin', 'extra-light', 'light',
'regular', 'medium', 'semi-bold', 'bold', 'extra-bold', 'black'. Default is |
required |
italic
|
Optional[bool]
|
Whether to use the italic variant. Default is |
None
|
allowed_formats
|
List[str]
|
List of acceptable font file formats. Defaults to ["woff2", "woff", "ttf", "otf"]. |
['woff2', 'woff', 'ttf', 'otf']
|
use_cache
|
bool
|
Whether or not to cache fonts (to make pyfonts faster). Default to |
True
|
danger_not_verify_ssl
|
bool
|
Whether or not to to skip SSL certificate on
|
False
|
Returns:
| Type | Description |
|---|---|
FontProperties
|
matplotlib.font_manager.FontProperties: A |
Examples:
```python
from pyfonts import load_google_font
font = load_google_font("Roboto") # default Roboto font
font = load_google_font("Roboto", weight="bold") # bold font
font = load_google_font("Roboto", italic=True) # italic font
font = load_google_font("Roboto", weight="bold", italic=True) # italic and bold
```
Examples
Basic usage
# mkdocs: render
import matplotlib.pyplot as plt
from pyfonts import load_google_font
font = load_google_font("Roboto") # default Roboto font
fig, ax = plt.subplots()
ax.text(
x=0.2,
y=0.3,
s="Hey there!",
size=30,
font=font
)
Custom font
# mkdocs: render
import matplotlib.pyplot as plt
from pyfonts import load_google_font
font = load_google_font("Roboto", weight="bold", italic=True) # italic and bold
fig, ax = plt.subplots()
ax.text(
x=0.2,
y=0.3,
s="Hey there!",
size=30,
font=font
)
Use multiple fonts
# mkdocs: render
import matplotlib.pyplot as plt
from pyfonts import load_google_font
font_bold = load_google_font("Roboto", weight="bold")
font_italic = load_google_font("Roboto", italic=True)
fig, ax = plt.subplots()
ax.text(
x=0.2,
y=0.3,
s="Hey bold!",
size=30,
font=font_bold
)
ax.text(
x=0.4,
y=0.6,
s="Hey italic!",
size=30,
font=font_italic
)
Fancy font
All fonts from Google font can be used: