Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8699958

Browse files
authored
Merge pull request #18633 from QuLogic/fix_linestyle_none
Support linestyle='none' in Patch
2 parents d2cf66d + ea6ca1a commit 8699958

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/matplotlib/patches.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,10 @@ def set_linestyle(self, ls):
409409
``'--'`` or ``'dashed'`` dashed line
410410
``'-.'`` or ``'dashdot'`` dash-dotted line
411411
``':'`` or ``'dotted'`` dotted line
412+
``'None'`` draw nothing
413+
``'none'`` draw nothing
414+
``' '`` draw nothing
415+
``''`` draw nothing
412416
=========================== =================
413417
414418
Alternatively a dash tuple of the following form can be provided::
@@ -424,6 +428,8 @@ def set_linestyle(self, ls):
424428
"""
425429
if ls is None:
426430
ls = "solid"
431+
if ls in [' ', '', 'none']:
432+
ls = 'None'
427433
self._linestyle = ls
428434
# get the unscaled dash pattern
429435
offset, ls = self._us_dashes = mlines._get_dash_pattern(ls)
@@ -540,7 +546,7 @@ def _bind_draw_path_function(self, renderer):
540546
gc.set_foreground(self._edgecolor, isRGBA=True)
541547

542548
lw = self._linewidth
543-
if self._edgecolor[3] == 0:
549+
if self._edgecolor[3] == 0 or self._linestyle == 'None':
544550
lw = 0
545551
gc.set_linewidth(lw)
546552
gc.set_dashes(self._dashoffset, self._dashes)

lib/matplotlib/tests/test_patches.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,32 @@ def test_patch_linestyle_accents():
238238
fig.canvas.draw()
239239

240240

241+
@check_figures_equal(extensions=['png'])
242+
def test_patch_linestyle_none(fig_test, fig_ref):
243+
circle = mpath.Path.unit_circle()
244+
245+
ax_test = fig_test.add_subplot()
246+
ax_ref = fig_ref.add_subplot()
247+
for i, ls in enumerate(['none', 'None', ' ', '']):
248+
path = mpath.Path(circle.vertices + i, circle.codes)
249+
patch = mpatches.PathPatch(path,
250+
linewidth=3, linestyle=ls,
251+
facecolor=(1, 0, 0),
252+
edgecolor=(0, 0, 1))
253+
ax_test.add_patch(patch)
254+
255+
patch = mpatches.PathPatch(path,
256+
linewidth=3, linestyle='-',
257+
facecolor=(1, 0, 0),
258+
edgecolor='none')
259+
ax_ref.add_patch(patch)
260+
261+
ax_test.set_xlim([-1, i + 1])
262+
ax_test.set_ylim([-1, i + 1])
263+
ax_ref.set_xlim([-1, i + 1])
264+
ax_ref.set_ylim([-1, i + 1])
265+
266+
241267
def test_wedge_movement():
242268
param_dict = {'center': ((0, 0), (1, 1), 'set_center'),
243269
'r': (5, 8, 'set_radius'),

0 commit comments

Comments
 (0)