Skip to content

plot

find_font_path(family, weight='normal', style='normal')

Find the file path of a font given its family, weight, and style.

Parameters:

Name Type Description Default
family str

Font family name (e.g., "Arial").

required
weight str

Font weight (e.g., "normal", "bold").

'normal'
style str

Font style (e.g., "normal", "italic").

'normal'

Returns:

Type Description
str | None

The file path of the matching font, or None if not found.

Source code in src/flygym/utils/plot.py
def find_font_path(
    family: str, weight: str = "normal", style: str = "normal"
) -> str | None:
    """
    Find the file path of a font given its family, weight, and style.

    Args:
        family: Font family name (e.g., "Arial").
        weight: Font weight (e.g., "normal", "bold").
        style:  Font style (e.g., "normal", "italic").

    Returns:
        The file path of the matching font, or None if not found.
    """
    import matplotlib.font_manager as fm

    font_props = fm.FontProperties(family=family, weight=weight, style=style)
    font_path = fm.findfont(font_props)
    return font_path