Skip to content

Commit ca2ecb2

Browse files
timhoffmtacaswell
authored andcommitted
Restructure _process_plot_varargs
Distinguish variants by desired output instead of calling command. This gives a better terminology for the new coordinate output variant. The command input was also used to create an error message containing the calling function name. This has been replaced by introspection.
1 parent ccaaa4a commit ca2ecb2

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

lib/matplotlib/axes/_base.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ class _process_plot_var_args:
213213
an arbitrary number of *x*, *y*, *fmt* are allowed
214214
"""
215215

216-
def __init__(self, command='plot'):
217-
_api.check_in_list(['plot', 'fill', 'mirror'], command=command)
218-
self.command = command
216+
def __init__(self, output='Line2D'):
217+
_api.check_in_list(['Line2D', 'Polygon', 'coordinates'], output=output)
218+
self.output = output
219219
self.set_prop_cycle(None)
220220

221221
def set_prop_cycle(self, cycler):
@@ -229,7 +229,7 @@ def __call__(self, axes, *args, data=None, return_kwargs=False, **kwargs):
229229

230230
for pos_only in "xy":
231231
if pos_only in kwargs:
232-
raise _api.kwarg_error(self.command, pos_only)
232+
raise _api.kwarg_error(inspect.stack()[1].function, pos_only)
233233

234234
if not args:
235235
return
@@ -332,18 +332,18 @@ def _setdefaults(self, defaults, kw):
332332
if kw.get(k, None) is None:
333333
kw[k] = defaults[k]
334334

335-
def _makeline(self, axes, x, y, kw, kwargs):
335+
def _make_line(self, axes, x, y, kw, kwargs):
336336
kw = {**kw, **kwargs} # Don't modify the original kw.
337337
self._setdefaults(self._getdefaults(kw), kw)
338338
seg = mlines.Line2D(x, y, **kw)
339339
return seg, kw
340340

341-
def _mirror(self, axes, x, y, kw, kwargs):
341+
def _make_coordinates(self, axes, x, y, kw, kwargs):
342342
kw = {**kw, **kwargs} # Don't modify the original kw.
343343
self._setdefaults(self._getdefaults(kw), kw)
344344
return (x, y), kw
345345

346-
def _makefill(self, axes, x, y, kw, kwargs):
346+
def _make_polygon(self, axes, x, y, kw, kwargs):
347347
# Polygon doesn't directly support unitized inputs.
348348
x = axes.convert_xunits(x)
349349
y = axes.convert_yunits(y)
@@ -501,15 +501,15 @@ def _plot_args(self, axes, tup, kwargs, *,
501501
if y.ndim == 1:
502502
y = y[:, np.newaxis]
503503

504-
if self.command == 'plot':
505-
make_artist = self._makeline
506-
elif self.command == 'fill':
504+
if self.output == 'Line2D':
505+
make_artist = self._make_line
506+
elif self.output == 'Polygon':
507507
kw['closed'] = kwargs.get('closed', True)
508-
make_artist = self._makefill
509-
elif self.command == 'mirror':
510-
make_artist = self._mirror
508+
make_artist = self._make_polygon
509+
elif self.output == 'coordinates':
510+
make_artist = self._make_coordinates
511511
else:
512-
_api.check_in_list(['plot', 'fill', 'mirror'], command=self.command)
512+
_api.check_in_list(['Line2D', 'Polygon', 'coordinates'], output=self.output)
513513

514514
ncx, ncy = x.shape[1], y.shape[1]
515515
if ncx > 1 and ncy > 1 and ncx != ncy:
@@ -1311,7 +1311,7 @@ def __clear(self):
13111311
self._use_sticky_edges = True
13121312

13131313
self._get_lines = _process_plot_var_args()
1314-
self._get_patches_for_fill = _process_plot_var_args('fill')
1314+
self._get_patches_for_fill = _process_plot_var_args('Polygon')
13151315

13161316
self._gridOn = mpl.rcParams['axes.grid']
13171317
# Swap children to minimize time we spend in an invalid state

0 commit comments

Comments
 (0)