8000 FIX: deal more gracefully with None kwargs in plot · matplotlib/matplotlib@a2b90a8 · GitHub
[go: up one dir, main page]

Skip to content

Commit a2b90a8

Browse files
committed
FIX: deal more gracefully with None kwargs in plot
These changes are to the methods on _process_plot_var_args In `_makelines` we get two dictionaries in from `_plot_args` which map to the keywords we generate internally and the kwargs passed in by the user. Previously the internally generated kwargs were passed to the Line2D `__init__` and the user supplied kwargs were passed to (eventually) `line.set` to bulk update the properties of the line. The change to `Line2D` is because `set_linestyle` internally calls `set_drawstyle`. What would happen in the case of `step` where the linestyle is `step-pre-` with the changes to `_base`: - set_linestyle would set the draw style to 'step' - set_drawstyle would re-set it to the default value Previously, both of these would be called in `__init__` with the default values and the updated with the user supplied values which masked the order issue in `__init__` (as most `Line2D` artists are made through the plot interface). closes #6173
1 parent c78ca18 commit a2b90a8

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,6 @@ def __call__(self, *args, **kwargs):
184184
ret = self._grab_next_args(*args, **kwargs)
185185
return ret
186186

187-
def set_lineprops(self, line, **kwargs):
188-
assert self.command == 'plot', 'set_lineprops only works with "plot"'
189-
line.set(**kwargs)
190-
191187
def set_patchprops(self, fill_poly, **kwargs):
192188
assert self.command == 'fill', 'set_patchprops only works with "fill"'
193189
fill_poly.set(**kwargs)
@@ -275,10 +271,10 @@ def _setdefaults(self, defaults, *kwargs):
275271
def _makeline(self, x, y, kw, kwargs):
276272
kw = kw.copy() # Don't modify the original kw.
277273
kwargs = kwargs.copy()
278-
default_dict = self._getdefaults(None, kw, kwargs)
279-
self._setdefaults(default_dict, kw, kwargs)
274+
kw.update(kwargs)
275+
default_dict = self._getdefaults(None, kw)
276+
self._setdefaults(default_dict, kw)
280277
seg = mlines.Line2D(x, y, **kw)
281-
self.set_lineprops(seg, **kwargs)
282278
return seg
283279

284280
def _makefill(self, x, y, kw, kwargs):

lib/matplotlib/lines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ def __init__(self, xdata, ydata,
332332

333333
self._dashSeq = None
334334

335-
self.set_linestyle(linestyle)
336335
self.set_drawstyle(drawstyle)
336+
self.set_linestyle(linestyle)
337337
self.set_linewidth(linewidth)
338338

339339
self._color = None

lib/matplotlib/tests/test_axes.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,11 +1790,11 @@ def test_boxplot_sym():
17901790
def test_boxplot_autorange_whiskers():
17911791
x = np.ones(140)
17921792
x = np.hstack([0, x, 2])
1793-
1793+
17941794
fig1, ax1 = plt.subplots()
17951795
ax1.boxplot([x, x], bootstrap=10000, notch=1)
17961796
ax1.set_ylim((-5, 5))
1797-
1797+
17981798
fig2, ax2 = plt.subplots()
17991799
ax2.boxplot([x, x], bootstrap=10000, notch=1, autorange=True)
18001800
ax2.set_ylim((-5, 5))
@@ -4237,6 +4237,19 @@ def test_axis_set_tick_params_labelsize_labelcolor():
42374237
assert axis_1.yaxis.majorTicks[0]._labelcolor == 'red'
42384238

42394239

4240+
@cleanup
4241+
def test_none_kwargs():
4242+
fig, ax = plt.subplots()
4243+
ln, = ax.plot(range(32), linestyle=None)
4244+
assert ln.get_linestyle() == '-'
4245+
4246+
4247+
@cleanup
4248+
def test_ls_ds_conflict():
4249+
assert_raises(ValueError, plt.plot, range(32),
4250+
linestyle='steps-pre:', drawstyle='steps-post')
4251+
4252+
42404253
@image_comparison(baseline_images=['date_timezone_x'], extensions=['png'])
42414254
def test_date_timezone_x():
42424255
# Tests issue 5575

0 commit comments

Comments
 (0)
0