Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion ultraplot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,50 @@
# Constants
COLORS_KEEP = ("red", "green", "blue", "cyan", "yellow", "magenta", "white", "black")

_ULTRAPLOT_STYLES = {
"poster": {
"font.size": 14,
"axes.titlesize": 18,
"axes.labelsize": 16,
"xtick.labelsize": 13,
"ytick.labelsize": 13,
"legend.fontsize": 13,
"figure.titlesize": 20,
"lines.linewidth": 2.0,
"lines.markersize": 6,
"figure.facecolor": "none",
"savefig.facecolor": "none",
"savefig.edgecolor": "none",
},
"dark_background": {
"figure.facecolor": "#111827",
"figure.edgecolor": "#111827",
"axes.facecolor": "#111827",
"axes.edgecolor": "#cbd5e1",
"axes.labelcolor": "#f8fafc",
"text.color": "#f8fafc",
"xtick.color": "#cbd5e1",
"ytick.color": "#cbd5e1",
"grid.color": "#475569",
"grid.alpha": 0.35,
"legend.facecolor": "#0f172a",
"legend.edgecolor": "#475569",
"savefig.facecolor": "#111827",
"savefig.edgecolor": "#111827",
"axes.prop_cycle": cycler.cycler(
color=(
"#60a5fa",
"#f59e0b",
"#34d399",
"#f472b6",
"#a78bfa",
"#f87171",
)
),
},
}
_ULTRAPLOT_STYLES["dark"] = _ULTRAPLOT_STYLES["dark_background"]

# Configurator docstrings
_rc_docstring = """
local : bool, default: True
Expand Down Expand Up @@ -305,6 +349,7 @@ def _get_style_dict(style, filter=True):
# copying the entire rcParams dict we just track the keys that were changed.
style_aliases = {
"538": "fivethirtyeight",
"dark": "dark_background",
"mpl20": "default",
"mpl15": "classic",
"original": mpl.matplotlib_fname(),
Expand Down Expand Up @@ -333,7 +378,9 @@ def _get_style_dict(style, filter=True):
kw = style
elif isinstance(style, str):
style = style_aliases.get(style, style)
if style in mstyle.library:
if style in _ULTRAPLOT_STYLES:
kw = _ULTRAPLOT_STYLES[style]
elif style in mstyle.library:
kw = mstyle.library[style]
else:
try:
Expand Down
15 changes: 15 additions & 0 deletions ultraplot/tests/test_config_helpers_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ def test_style_dict_and_inference_helpers():
inline_style = config._get_style_dict({"axes.facecolor": "black"})
assert inline_style["axes.facecolor"] == "black"

poster_style = config._get_style_dict("poster")
assert poster_style["figure.facecolor"] == "none"
assert poster_style["font.size"] > config._get_style_dict("default")["font.size"]

dark_style = config._get_style_dict("dark_background")
assert dark_style["axes.facecolor"] == "#111827"
assert dark_style["text.color"] == "#f8fafc"

dark_alias_style = config._get_style_dict("dark")
assert dark_alias_style["axes.facecolor"] == dark_style["axes.facecolor"]

combined = {"xtick.labelsize": 9, "axes.titlesize": 14, "text.color": "red"}
inferred = config._infer_ultraplot_dict(combined)
assert inferred["tick.labelsize"] == 9
Expand Down Expand Up @@ -75,6 +86,10 @@ def test_configurator_validation_item_dicts_and_context(tmp_path):
assert kw_ultraplot["title.size"] == pytest.approx(14)
assert kw_ultraplot["grid.labelcolor"] == "red"

kw_ultraplot, kw_matplotlib = cfg._get_item_dicts("style", "dark_background")
assert kw_matplotlib["axes.facecolor"] == "#111827"
assert kw_ultraplot["grid.labelcolor"] == "#f8fafc"

kw_ultraplot, kw_matplotlib = cfg._get_item_dicts("font.size", 12)
assert "abc.size" in kw_ultraplot
assert kw_matplotlib["font.size"] == 12
Expand Down