MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _process_plot_var_args

Class _process_plot_var_args

lib/matplotlib/axes/_base.py:241–554  ·  view source on GitHub ↗

Process variable length arguments to `~.Axes.plot`, to support :: plot(t, s) plot(t1, s1, t2, s2) plot(t1, s1, 'ko', t2, s2) plot(t1, s1, 'ko', t2, s2, 'r--', t3, e3) an arbitrary number of *x*, *y*, *fmt* are allowed

Source from the content-addressed store, hash-verified

239
240
241class _process_plot_var_args:
242 """
243 Process variable length arguments to `~.Axes.plot`, to support ::
244
245 plot(t, s)
246 plot(t1, s1, t2, s2)
247 plot(t1, s1, 'ko', t2, s2)
248 plot(t1, s1, 'ko', t2, s2, 'r--', t3, e3)
249
250 an arbitrary number of *x*, *y*, *fmt* are allowed
251 """
252
253 def __init__(self, output='Line2D'):
254 _api.check_in_list(['Line2D', 'Polygon', 'coordinates'], output=output)
255 self.output = output
256 self.set_prop_cycle(None)
257
258 def set_prop_cycle(self, cycler):
259 self._prop_cycle = _PropCycle(mpl._val_or_rc(cycler, 'axes.prop_cycle'))
260
261 def __call__(self, axes, *args, data=None, return_kwargs=False, **kwargs):
262 axes._process_unit_info(kwargs=kwargs)
263
264 for pos_only in "xy":
265 if pos_only in kwargs:
266 raise _api.kwarg_error(inspect.stack()[1].function, pos_only)
267
268 if not args:
269 return
270
271 if data is None: # Process dict views
272 args = [cbook.sanitize_sequence(a) for a in args]
273 else: # Process the 'data' kwarg.
274 replaced = [mpl._replacer(data, arg) for arg in args]
275 if len(args) == 1:
276 label_namer_idx = 0
277 elif len(args) == 2: # Can be x, y or y, c.
278 # Figure out what the second argument is.
279 # 1) If the second argument cannot be a format shorthand, the
280 # second argument is the label_namer.
281 # 2) Otherwise (it could have been a format shorthand),
282 # a) if we did perform a substitution, emit a warning, and
283 # use it as label_namer.
284 # b) otherwise, it is indeed a format shorthand; use the
285 # first argument as label_namer.
286 try:
287 _process_plot_format(args[1])
288 except ValueError: # case 1)
289 label_namer_idx = 1
290 else:
291 if replaced[1] is not args[1]: # case 2a)
292 _api.warn_external(
293 f"Second argument {args[1]!r} is ambiguous: could "
294 f"be a format string but is in 'data'; using as "
295 f"data. If it was intended as data, set the "
296 f"format string to an empty string to suppress "
297 f"this warning. If it was intended as a format "
298 f"string, explicitly pass the x-values as well. "

Callers 1

__clearMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…