From 15a6f1c0f4db7b8b5a66fda99082a41a4b57742a Mon Sep 17 00:00:00 2001 From: Prajval Arora Date: Tue, 13 Oct 2026 16:50:25 -0700 Subject: [PATCH 1/2] fix: consume Matplotlib format markers --- src/machinevisiontoolbox/base/graphics.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/machinevisiontoolbox/base/graphics.py b/src/machinevisiontoolbox/base/graphics.py index fd000e31..aee4e292 100644 --- a/src/machinevisiontoolbox/base/graphics.py +++ b/src/machinevisiontoolbox/base/graphics.py @@ -1014,6 +1014,7 @@ def parse_matplotlib_fmt(fmt: str): marker_match = re.search(marker_pattern, working_fmt) if marker_match: res["marker"] = marker_match.group(0) + working_fmt = working_fmt.replace(res["marker"], "", 1) if len(working_fmt.strip()) > 0: raise ValueError( From 095138950b34aad29767641e02cc8b0f31e2b2a6 Mon Sep 17 00:00:00 2001 From: Prajval Arora Date: Tue, 13 Oct 2026 16:50:43 -0700 Subject: [PATCH 2/2] test: cover compact marker formats and invalid leftovers Check marker formats, tuple input, option precedence and rejection of unmatched characters. --- tests/base/test_mpl_styling.py | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/base/test_mpl_styling.py diff --git a/tests/base/test_mpl_styling.py b/tests/base/test_mpl_styling.py new file mode 100644 index 00000000..cc317e14 --- /dev/null +++ b/tests/base/test_mpl_styling.py @@ -0,0 +1,42 @@ +"""Compact Matplotlib markers must be consumed before checking leftovers.""" + +import matplotlib.pyplot as plt +import pytest + +from machinevisiontoolbox.base import mpl_styling + + +@pytest.mark.parametrize( + "fmt, expected", + [ + ("o", {"marker": "o"}), + ("ro--", {"color": "r", "marker": "o", "linestyle": "--"}), + ("g^:", {"color": "g", "marker": "^", "linestyle": ":"}), + ("-.b*", {"color": "b", "marker": "*", "linestyle": "-."}), + (("ro--",), {"color": "r", "marker": "o", "linestyle": "--"}), + ], +) +def test_marker_formats(fmt, expected): + options = mpl_styling(fmt, {}, {}) + assert options == expected + fig, ax = plt.subplots() + try: + (line,) = ax.plot([0, 1], [0, 1], **options) + assert line.get_marker() == expected["marker"] + finally: + plt.close(fig) + + +@pytest.mark.parametrize("fmt", ["roo", "r?", "ro--?"]) +def test_unrecognized_components_still_raise(fmt): + with pytest.raises(ValueError, match="Unrecognized format components"): + mpl_styling(fmt, {}, {}) + + +def test_keyword_options_override_compact_marker(): + assert mpl_styling("ro--", {"linewidth": 2}, {"marker": "x"}) == { + "color": "r", + "marker": "x", + "linestyle": "--", + "linewidth": 2, + }