Skip to content

style

Opinionated matplotlib style defaults.

available_fonts() -> list[str]

Returns a list of available fonts.

Source code in src/jetplot/style.py
141
142
143
def available_fonts() -> list[str]:
    """Returns a list of available fonts."""
    return sorted(set([f.name for f in fm.fontManager.ttflist]))  # pyrefly: ignore

install_fonts(filepath: str) -> None

Installs .ttf fonts in the given folder.

Source code in src/jetplot/style.py
146
147
148
149
150
151
152
153
154
155
156
157
158
159
def install_fonts(filepath: str) -> None:
    """Installs .ttf fonts in the given folder."""

    original_fonts = set(available_fonts())
    font_files = fm.findSystemFonts(fontpaths=[filepath])

    for font_file in font_files:
        fm.fontManager.addfont(font_file)  # pyrefly: ignore

    new_fonts = set(available_fonts()) - original_fonts
    if new_fonts:
        print(f"Added the following fonts: {', '.join(new_fonts)}")
    else:
        print("No new fonts added.")

set_colors(bg: ColorType, fg: ColorType, text: ColorType) -> None

Set background/foreground colorscheme.

Source code in src/jetplot/style.py
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def set_colors(bg: ColorType, fg: ColorType, text: ColorType) -> None:
    """Set background/foreground colorscheme."""
    rcParams.update(
        {
            "figure.facecolor": bg,
            "figure.edgecolor": bg,
            "axes.facecolor": bg,
            "savefig.facecolor": bg,
            "savefig.edgecolor": bg,
            "axes.edgecolor": fg,
            "axes.labelcolor": text,
            "xtick.color": fg,
            "ytick.color": fg,
            "legend.edgecolor": fg,
            "grid.color": fg,
            "text.color": text,
        }
    )

set_defaults(*, bg: ColorType, fg: ColorType, text: ColorType, cycler_colors: c.Palette, defaults: Mapping[str, Any] = STYLE_DEFAULTS, font: str = 'Helvetica') -> None

Sets matplotlib defaults.

Source code in src/jetplot/style.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
def set_defaults(
    *,
    bg: ColorType,
    fg: ColorType,
    text: ColorType,
    cycler_colors: c.Palette,
    defaults: Mapping[str, Any] = STYLE_DEFAULTS,
    font: str = "Helvetica",
) -> None:
    """Sets matplotlib defaults."""
    rcParams.update(defaults)
    set_colors(bg, fg, text)
    rcParams["axes.prop_cycle"] = cycler(color=cycler_colors)

    try:
        set_font(font)
    except ValueError:
        pass

set_dpi(dpi: int) -> None

Sets the figure DPI.

Source code in src/jetplot/style.py
108
109
110
def set_dpi(dpi: int) -> None:
    """Sets the figure DPI."""
    rcParams["figure.dpi"] = dpi

set_font(fontname: str) -> None

Specifies the matplotlib default font.

Source code in src/jetplot/style.py
 99
100
101
102
103
104
105
def set_font(fontname: str) -> None:
    """Specifies the matplotlib default font."""

    if fontname not in available_fonts():
        raise ValueError(f"Font {fontname} not found.")

    rcParams["font.family"] = fontname