From 307d896091f886ef0642aefbae3e341304f3834a Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Wed, 4 Feb 2026 07:29:23 +1000 Subject: [PATCH 1/2] Add rc default for text borderstyle --- ultraplot/axes/base.py | 5 +++-- ultraplot/internals/labels.py | 3 ++- ultraplot/internals/rcsetup.py | 7 +++++++ ultraplot/tests/test_axes.py | 26 ++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/ultraplot/axes/base.py b/ultraplot/axes/base.py index b4462ed32..9ccb5605f 100644 --- a/ultraplot/axes/base.py +++ b/ultraplot/axes/base.py @@ -3823,7 +3823,7 @@ def text( bordercolor="w", borderwidth=2, borderinvert=False, - borderstyle="miter", + borderstyle=None, bboxcolor="w", bboxstyle="round", bboxalpha=0.5, @@ -3853,7 +3853,7 @@ def text( The color of the text border. borderinvert : bool, optional If ``True``, the text and border colors are swapped. - borderstyle : {'miter', 'round', 'bevel'}, optional + borderstyle : {'miter', 'round', 'bevel'}, default: :rc:`text.borderstyle` The `line join style \\ `__ used for the border. @@ -3900,6 +3900,7 @@ def text( kwargs.update(_pop_props(kwargs, "text")) # Update the text object using a monkey patch + borderstyle = _not_none(borderstyle, rc["text.borderstyle"]) obj = func(*args, transform=transform, **kwargs) obj.update = labels._update_label.__get__(obj) obj.update( diff --git a/ultraplot/internals/labels.py b/ultraplot/internals/labels.py index 8b7cb851e..a37c94360 100644 --- a/ultraplot/internals/labels.py +++ b/ultraplot/internals/labels.py @@ -6,6 +6,7 @@ import matplotlib.text as mtext from matplotlib.font_manager import FontProperties +from ..config import rc from . import ic # noqa: F401 @@ -64,7 +65,7 @@ def _update_label(text, props=None, **kwargs): bordercolor = props.pop("bordercolor", "w") borderinvert = props.pop("borderinvert", False) borderwidth = props.pop("borderwidth", 2) - borderstyle = props.pop("borderstyle", "miter") + borderstyle = props.pop("borderstyle", rc["text.borderstyle"]) if border: facecolor, bgcolor = text.get_color(), bordercolor diff --git a/ultraplot/internals/rcsetup.py b/ultraplot/internals/rcsetup.py index e811159a6..84491f1f9 100644 --- a/ultraplot/internals/rcsetup.py +++ b/ultraplot/internals/rcsetup.py @@ -706,6 +706,7 @@ def copy(self): "sawtooth", "roundtooth", ) +_validate_joinstyle = _validate_belongs("miter", "round", "bevel") if hasattr(msetup, "_validate_linestyle"): # fancy validation including dashes _validate_linestyle = msetup._validate_linestyle else: # no dashes allowed then but no big deal @@ -1043,6 +1044,12 @@ def copy(self): _validate_pt, "Width of the white border around a-b-c labels.", ), + "text.borderstyle": ( + "miter", + _validate_joinstyle, + "Join style for text border strokes. Must be one of " + "``'miter'``, ``'round'``, or ``'bevel'``.", + ), "abc.bbox": ( False, _validate_bool, diff --git a/ultraplot/tests/test_axes.py b/ultraplot/tests/test_axes.py index f1fad637a..004f7683a 100644 --- a/ultraplot/tests/test_axes.py +++ b/ultraplot/tests/test_axes.py @@ -4,6 +4,7 @@ """ import numpy as np import pytest +import matplotlib.patheffects as mpatheffects import ultraplot as uplt from ultraplot.internals.warnings import UltraPlotWarning @@ -131,6 +132,31 @@ def test_cartesian_format_all_units_types(): ax.format(**kwargs) +def _get_text_stroke_joinstyle(text): + for effect in text.get_path_effects(): + if isinstance(effect, mpatheffects.Stroke): + for attr in ("joinstyle", "_joinstyle"): + if hasattr(effect, attr): + return getattr(effect, attr) + if hasattr(effect, "_gc"): + return effect._gc.get("joinstyle") + return None + + +def test_text_borderstyle_rc_default(): + fig, ax = uplt.subplots() + with uplt.rc.context({"text.borderstyle": "round"}): + txt = ax.text(0.5, 0.5, "A", border=True) + assert _get_text_stroke_joinstyle(txt) == "round" + + +def test_text_borderstyle_overrides_rc(): + fig, ax = uplt.subplots() + with uplt.rc.context({"text.borderstyle": "round"}): + txt = ax.text(0.5, 0.5, "A", border=True, borderstyle="bevel") + assert _get_text_stroke_joinstyle(txt) == "bevel" + + def test_dualx_log_transform_is_finite(): """ Ensure dualx transforms remain finite on log axes. From a73be69fcd0d418185b9aa57d83d07a441d313b3 Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Wed, 4 Feb 2026 13:56:23 +1000 Subject: [PATCH 2/2] Set correct default --- ultraplot/internals/rcsetup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ultraplot/internals/rcsetup.py b/ultraplot/internals/rcsetup.py index 0597f0f02..9c1889a36 100644 --- a/ultraplot/internals/rcsetup.py +++ b/ultraplot/internals/rcsetup.py @@ -1046,7 +1046,7 @@ def copy(self): "Width of the white border around a-b-c labels.", ), "text.borderstyle": ( - "miter", + "bevel", _validate_joinstyle, "Join style for text border strokes. Must be one of " "``'miter'``, ``'round'``, or ``'bevel'``.",