From c7e9cdc5af73d6e9313fe25ed77e933aa080fb09 Mon Sep 17 00:00:00 2001 From: Anton Burenko Date: Wed, 22 Mar 2023 14:28:02 +0100 Subject: [PATCH 1/3] Add fix --- seaborn/_marks/base.py | 3 +++ tests/_marks/test_dot.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/seaborn/_marks/base.py b/seaborn/_marks/base.py index 324d0221e7..8c064f5998 100644 --- a/seaborn/_marks/base.py +++ b/seaborn/_marks/base.py @@ -12,6 +12,7 @@ from pandas import DataFrame from matplotlib.artist import Artist +from seaborn._compat import MarkerStyle from seaborn._core.scales import Scale from seaborn._core.properties import ( PROPERTIES, @@ -182,6 +183,8 @@ def _resolve( if return_array: feature = np.asarray(feature) + if name == "marker": + feature = [MarkerStyle(f) for f in feature] return feature if feature.depend is not None: diff --git a/tests/_marks/test_dot.py b/tests/_marks/test_dot.py index 49b5e8f129..21c9ff91da 100644 --- a/tests/_marks/test_dot.py +++ b/tests/_marks/test_dot.py @@ -63,6 +63,24 @@ def test_filled_unfilled_mix(self): expected = [mark.edgewidth, mark.stroke] assert_array_equal(points.get_linewidths(), expected) + def test_none_marker(self): + + x = [1, 2] + y = [4, 5] + marker = ["o", "s"] + + mark = Dot(edgecolor="w", stroke=2, edgewidth=1) + p = Plot(x=x, y=y).add(mark, marker=marker).scale(marker=None).plot() + ax = p._figure.axes[0] + points, = ax.collections + C0, *_ = p._theme["axes.prop_cycle"].by_key()["color"] + self.check_offsets(points, x, y) + self.check_colors("face", points, [C0, to_rgba(C0, 0)], 1) + self.check_colors("edge", points, ["w", C0], 1) + + expected = [mark.edgewidth, mark.stroke] + assert_array_equal(points.get_linewidths(), expected) + def test_missing_coordinate_data(self): x = [1, float("nan"), 3] From 04a1d7d5bad7014caccd4868ce6ac0eee5c86e28 Mon Sep 17 00:00:00 2001 From: Anton Burenko Date: Wed, 22 Mar 2023 15:52:33 +0100 Subject: [PATCH 2/3] Simplify test --- tests/_marks/test_dot.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/_marks/test_dot.py b/tests/_marks/test_dot.py index 21c9ff91da..3c0a7c684a 100644 --- a/tests/_marks/test_dot.py +++ b/tests/_marks/test_dot.py @@ -76,10 +76,6 @@ def test_none_marker(self): C0, *_ = p._theme["axes.prop_cycle"].by_key()["color"] self.check_offsets(points, x, y) self.check_colors("face", points, [C0, to_rgba(C0, 0)], 1) - self.check_colors("edge", points, ["w", C0], 1) - - expected = [mark.edgewidth, mark.stroke] - assert_array_equal(points.get_linewidths(), expected) def test_missing_coordinate_data(self): From 576ce2e6cbfeba0ad343806c8c8628d6bde68ed7 Mon Sep 17 00:00:00 2001 From: Anton Burenko Date: Thu, 30 Mar 2023 23:43:38 +0200 Subject: [PATCH 3/3] Improve test --- tests/_marks/test_dot.py | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/tests/_marks/test_dot.py b/tests/_marks/test_dot.py index 3c0a7c684a..d09717bb18 100644 --- a/tests/_marks/test_dot.py +++ b/tests/_marks/test_dot.py @@ -4,7 +4,7 @@ from numpy.testing import assert_array_equal from seaborn.palettes import color_palette -from seaborn._core.plot import Plot +from seaborn._core.plot import Plot, Plotter from seaborn._marks.dot import Dot, Dots @@ -53,29 +53,16 @@ def test_filled_unfilled_mix(self): mark = Dot(edgecolor="w", stroke=2, edgewidth=1) p = Plot(x=x, y=y).add(mark, marker=marker).scale(marker=shapes).plot() - ax = p._figure.axes[0] - points, = ax.collections - C0, *_ = p._theme["axes.prop_cycle"].by_key()["color"] - self.check_offsets(points, x, y) - self.check_colors("face", points, [C0, to_rgba(C0, 0)], None) - self.check_colors("edge", points, ["w", C0], 1) - - expected = [mark.edgewidth, mark.stroke] - assert_array_equal(points.get_linewidths(), expected) - - def test_none_marker(self): + self._test_filled_unfilled_mix(x, y, p, mark) + def test_identity_marker(self): x = [1, 2] y = [4, 5] - marker = ["o", "s"] + shapes = ["o", "x"] mark = Dot(edgecolor="w", stroke=2, edgewidth=1) - p = Plot(x=x, y=y).add(mark, marker=marker).scale(marker=None).plot() - ax = p._figure.axes[0] - points, = ax.collections - C0, *_ = p._theme["axes.prop_cycle"].by_key()["color"] - self.check_offsets(points, x, y) - self.check_colors("face", points, [C0, to_rgba(C0, 0)], 1) + p = Plot(x=x, y=y).add(mark, marker=shapes).scale(marker=None).plot() + self._test_filled_unfilled_mix(x, y, p, mark) def test_missing_coordinate_data(self): @@ -99,6 +86,17 @@ def test_missing_semantic_data(self, prop): points, = ax.collections self.check_offsets(points, [1, 3], [5, 4]) + def _test_filled_unfilled_mix(self, x, y, p: Plotter, mark: Dot): + ax = p._figure.axes[0] + points, = ax.collections + C0, *_ = p._theme["axes.prop_cycle"].by_key()["color"] + self.check_offsets(points, x, y) + self.check_colors("face", points, [C0, to_rgba(C0, 0)], None) + self.check_colors("edge", points, ["w", C0], 1) + + expected = [mark.edgewidth, mark.stroke] + assert_array_equal(points.get_linewidths(), expected) + class TestDots(DotBase):