Skip to content

Commit 8c206c6

Browse files
tacaswellmeeseeksmachine
authored andcommitted
Backport PR matplotlib#31587: FIX: scatter with ls="" crashes on PDF savefig
1 parent f55c3f1 commit 8c206c6

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

lib/matplotlib/lines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _get_dash_pattern(style):
3636
if isinstance(style, str):
3737
style = ls_mapper.get(style, style)
3838
# un-dashed styles
39-
if style in ['solid', 'None']:
39+
if style in ['solid', 'None', 'none', '', ' ']:
4040
offset = 0
4141
dashes = None
4242
# dashed styles

lib/matplotlib/tests/test_collections.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,17 @@ def test_set_wrong_linestyle():
704704
c.set_linestyle('fuzzy')
705705

706706

707+
@pytest.mark.parametrize('ls', ['', ' ', 'none'])
708+
def test_scatter_empty_linestyle_pdf(ls):
709+
# Regression test: '', ' ', and 'none' are documented "draw nothing"
710+
# linestyle aliases but were not recognized by _get_dash_pattern, causing
711+
# savefig to PDF to crash with "zero-size array to reduction operation maximum".
712+
plt.switch_backend('pdf')
713+
fig, ax = plt.subplots()
714+
ax.scatter([0, 1], [0, 1], ls=ls)
715+
fig.savefig(io.BytesIO())
716+
717+
707718
@mpl.style.context('default')
708719
def test_capstyle():
709720
col = mcollections.PathCollection([])

0 commit comments

Comments
 (0)