From 2be931bb769dadb0a63ca35f38be6c52d48dfac3 Mon Sep 17 00:00:00 2001 From: Rezangyal Date: Sun, 20 Dec 2015 00:30:32 +0100 Subject: [PATCH 1/2] Patch now support the "None" linestyle If patch.linestyle is "none", "None", " ", "" then no edge rendered (as in Line2D). --- lib/matplotlib/patches.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index 63be433c542b..8dcaea286db5 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -409,6 +409,10 @@ def set_linestyle(self, ls): ``'--'`` or ``'dashed'`` dashed line ``'-.'`` or ``'dashdot'`` dash-dotted line ``':'`` or ``'dotted'`` dotted line + ``'None'`` draw nothing + ``'none'`` draw nothing + ``' '`` draw nothing + ``''`` draw nothing =========================== ================= Alternatively a dash tuple of the following form can be provided:: @@ -424,6 +428,8 @@ def set_linestyle(self, ls): """ if ls is None: ls = "solid" + if ls in [' ', '', 'none']: + ls = 'None' self._linestyle = ls # get the unscaled dash pattern offset, ls = self._us_dashes = mlines._get_dash_pattern(ls) @@ -540,7 +546,7 @@ def _bind_draw_path_function(self, renderer): gc.set_foreground(self._edgecolor, isRGBA=True) lw = self._linewidth - if self._edgecolor[3] == 0: + if self._edgecolor[3] == 0 or self._linestyle == 'None': lw = 0 gc.set_linewidth(lw) gc.set_dashes(self._dashoffset, self._dashes) From ea6ca1a8469baf800e80fb606b1dc81b4aa0a329 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Fri, 2 Oct 2020 03:50:03 -0400 Subject: [PATCH 2/2] Add a test for Patch accepting 'none' linestyle. --- lib/matplotlib/tests/test_patches.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/matplotlib/tests/test_patches.py b/lib/matplotlib/tests/test_patches.py index 0440a52ca37b..2a908098364e 100644 --- a/lib/matplotlib/tests/test_patches.py +++ b/lib/matplotlib/tests/test_patches.py @@ -238,6 +238,32 @@ def test_patch_linestyle_accents(): fig.canvas.draw() +@check_figures_equal(extensions=['png']) +def test_patch_linestyle_none(fig_test, fig_ref): + circle = mpath.Path.unit_circle() + + ax_test = fig_test.add_subplot() + ax_ref = fig_ref.add_subplot() + for i, ls in enumerate(['none', 'None', ' ', '']): + path = mpath.Path(circle.vertices + i, circle.codes) + patch = mpatches.PathPatch(path, + linewidth=3, linestyle=ls, + facecolor=(1, 0, 0), + edgecolor=(0, 0, 1)) + ax_test.add_patch(patch) + + patch = mpatches.PathPatch(path, + linewidth=3, linestyle='-', + facecolor=(1, 0, 0), + edgecolor='none') + ax_ref.add_patch(patch) + + ax_test.set_xlim([-1, i + 1]) + ax_test.set_ylim([-1, i + 1]) + ax_ref.set_xlim([-1, i + 1]) + ax_ref.set_ylim([-1, i + 1]) + + def test_wedge_movement(): param_dict = {'center': ((0, 0), (1, 1), 'set_center'), 'r': (5, 8, 'set_radius'),