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

Skip to content

Commit 6357245

Browse files
committed
MNT: add exception for invalid kwargs to LogScale
1 parent def5e9a commit 6357245

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/matplotlib/scale.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,12 @@ def __init__(self, axis, **kwargs):
235235
subs = kwargs.pop('subsy', None)
236236
nonpos = kwargs.pop('nonposy', 'clip')
237237

238+
if len(kwargs):
239+
raise ValueError(("provided too many kwargs, can only pass "
240+
"{'basex', 'subsx', nonposx'} or "
241+
"{'basey', 'subsy', nonposy'}. You passed ") +
242+
"{!r}".format(kwargs))
243+
238244
if nonpos not in ['mask', 'clip']:
239245
raise ValueError("nonposx, nonposy kwarg must be 'mask' or 'clip'")
240246

lib/matplotlib/tests/test_scale.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import matplotlib.pyplot as plt
55
import numpy as np
66
import io
7+
import pytest
78

89

910
@image_comparison(baseline_images=['log_scales'], remove_text=True)
@@ -65,3 +66,10 @@ def test_logscale_mask():
6566
ax.plot(np.exp(-xs**2))
6667
fig.canvas.draw()
6768
ax.set(yscale="log")
69+
70+
71+
def test_extra_kwargs_raise():
72+
fig, ax = plt.subplots()
73+
with pytest.raises(ValueError):
74+
ax.set_yscale('log', nonpos='mask')
75+

0 commit comments

Comments
 (0)