From fee98bc9a9f048b087acef3300e417a7eb26e2ab Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Tue, 23 Jun 2026 21:00:37 +1000 Subject: [PATCH] Preserve explicit axes frame styling across reformatting --- ultraplot/axes/_formatting.py | 20 ++++++++++++++++-- ultraplot/tests/test_axes_alt_styles.py | 28 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/ultraplot/axes/_formatting.py b/ultraplot/axes/_formatting.py index 298724d00..655fee713 100644 --- a/ultraplot/axes/_formatting.py +++ b/ultraplot/axes/_formatting.py @@ -6,8 +6,24 @@ import inspect _AXIS_STYLE_FIELD_TEMPLATES = { - "color": ("{axis}color", "color", "{axis}ec", "ec", "{axis}edgecolor", "edgecolor"), - "linewidth": ("{axis}linewidth", "linewidth", "{axis}lw", "lw"), + "color": ( + "{axis}color", + "color", + "{axis}ec", + "ec", + "{axis}edgecolor", + "edgecolor", + "axesec", + "axesedgecolor", + ), + "linewidth": ( + "{axis}linewidth", + "linewidth", + "{axis}lw", + "lw", + "axeslw", + "axeslinewidth", + ), "rotation": ("{axis}rotation", "rotation"), "spineloc": ("{axis}spineloc", "{axis}loc"), "tickloc": ("{axis}tickloc",), diff --git a/ultraplot/tests/test_axes_alt_styles.py b/ultraplot/tests/test_axes_alt_styles.py index 492872db2..014fe1753 100644 --- a/ultraplot/tests/test_axes_alt_styles.py +++ b/ultraplot/tests/test_axes_alt_styles.py @@ -197,6 +197,34 @@ def test_subplots_preserve_generic_tickcolor_across_later_axis_color(): } == {mcolors.to_rgba("C1")} +def test_subplots_preserve_per_axes_axesedgecolor_on_reformat(): + fig, axs = uplt.subplots(ncols=2) + expected = [] + for i, ax in enumerate(axs): + color = f"C{i}" + expected.append(mcolors.to_rgba(color)) + ax.format(axesedgecolor=color) + + axs.format(title="Axes edge color") + + actual = [mcolors.to_rgba(ax.spines["left"].get_edgecolor()) for ax in axs] + assert actual == expected + + +def test_subplots_preserve_per_axes_axeslinewidth_on_reformat(): + fig, axs = uplt.subplots(ncols=2) + expected = [] + for i, ax in enumerate(axs): + linewidth = i + 1 + expected.append(linewidth) + ax.format(axeslinewidth=linewidth) + + axs.format(title="Axes line width") + + actual = [ax.spines["left"].get_linewidth() for ax in axs] + assert actual == expected + + def test_subplots_apply_generic_labelcolor(): fig, axs = uplt.subplots() ax = axs[0]