Skip to content

Commit 9265aa0

Browse files
committed
BUG: Allowing unknown drawstyles. Fixes #6143.
Added a check that forbids `drawstyle` keywords that are not listed in the documentation. Added tests to mimic linestyle tests. Added self to mailmap.
1 parent 7f21cc5 commit 9265aa0

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Jens Hedegaard Nielsen <jenshnielsen@gmail.com> <jens.nielsen@ucl.ac.uk>
2727
John Hunter <jdh2358@gmail.com>
2828
Jorrit Wronski <jowr@mek.dtu.dk>
2929
Jouni K. Seppänen <jks@iki.fi>
30+
Joseph Fox-Rabinovitz <jfoxrabinovitz@gmail.com> Mad Physicist <madphysicist@users.noreply.github.com>
3031
Julien Schueller <julien.schueller@gmail.com> <schueller@porsche-l64.phimeca.lan>
3132
Julien Schueller <julien.schueller@gmail.com> <schueller@bx-l64.phimeca.lan>
3233
Kevin Davies <kdavies4@gmail.com> <daviesk24@yahoo.com>

lib/matplotlib/lines.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,9 @@ def set_drawstyle(self, drawstyle):
985985
ACCEPTS: ['default' | 'steps' | 'steps-pre' | 'steps-mid' |
986986
'steps-post']
987987
"""
988+
if drawstyle not in self.drawStyles:
989+
raise ValueError('Unrecognized drawstyle ' +
990+
' '.join(self.drawStyleKeys))
988991
if self._drawstyle != drawstyle:
989992
self.stale = True
990993
self._drawstyle = drawstyle

lib/matplotlib/tests/test_lines.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,29 @@ def test_valid_linestyles():
118118
line.set_linestyle('aardvark')
119119

120120

121+
@cleanup
122+
def test_drawstyle_variants():
123+
fig = plt.figure()
124+
ax = fig.add_subplot(1, 1, 1)
125+
for ds in ("default", "steps-mid", "steps-pre", "steps-post",
126+
"steps"):
127+
ax.plot(range(10), drawstyle=ds)
128+
129+
fig.canvas.draw()
130+
assert True
131+
132+
133+
@cleanup
134+
def test_valid_drawstyles():
135+
if sys.version_info[:2] < (2, 7):
136+
raise nose.SkipTest("assert_raises as context manager "
137+
"not supported with Python < 2.7")
138+
139+
line = mlines.Line2D([], [])
140+
with assert_raises(ValueError):
141+
line.set_drawstyle('foobar')
142+
143+
121144
@image_comparison(baseline_images=['line_collection_dashes'], remove_text=True)
122145
def test_set_line_coll_dash_image():
123146
fig = plt.figure()

0 commit comments

Comments
 (0)