Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Cleanup and document _plot_args()#19278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -403,12 +403,53 @@ def _makefill(self, x, y, kw, kwargs): | ||
return seg, kwargs | ||
def _plot_args(self, tup, kwargs, return_kwargs=False): | ||
""" | ||
Process the arguments of ``plot([x], y, [fmt], **kwargs)`` calls. | ||
This processes a single set of ([x], y, [fmt]) parameters; i.e. for | ||
``plot(x, y, x2, y2)`` it will be called twice. Once for (x, y) and | ||
once for (x2, y2). | ||
x and y may be 2D and thus can still represent multiple datasets. | ||
For multiple datasets, if the keyword argument *label* is a list, this | ||
will unpack the list and assign the individual labels to the datasets. | ||
Parameters | ||
---------- | ||
tup : tuple | ||
A tuple of the positional parameters. This can be one of | ||
- (y,) | ||
- (x, y) | ||
- (y, fmt) | ||
- (x, y, fmt) | ||
kwargs : dict | ||
The keyword arguments passed to ``plot()``. | ||
return_kwargs : bool | ||
If true, return the effective keyword arguments after label | ||
unpacking as well. | ||
Returns | ||
------- | ||
result | ||
If *return_kwargs* is false, a list of Artists representing the | ||
dataset(s). | ||
If *return_kwargs* is true, a list of (Artist, effective_kwargs) | ||
representing the dataset(s). See *return_kwargs*. | ||
The Artist is either `.Line2D` (if called from ``plot()``) or | ||
`.Polygon` otherwise. | ||
""" | ||
if len(tup) > 1 and isinstance(tup[-1], str): | ||
# xy is tup with fmt stripped (could still be (y,) only) | ||
*xy, fmt = tup | ||
linestyle, marker, color = _process_plot_format(fmt) | ||
elif len(tup) == 3: | ||
raise ValueError('third arg must be a format string') | ||
else: | ||
xy = tup | ||
linestyle, marker, color = None, None, None | ||
# Don't allow any None value; these would be up-converted to one | ||
@@ -417,16 +458,16 @@ def _plot_args(self, tup, kwargs, return_kwargs=False): | ||
raise ValueError("x, y, and format string must not be None") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This would never have checked whether There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. For There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Ah yes, because the length checks are different. | ||
kw = {} | ||
forprop_name, val in zip(('linestyle', 'marker', 'color'), | ||
(linestyle, marker, color)): | ||
ifval is not None: | ||
kw[prop_name] =val | ||
if len(xy) == 2: | ||
x = _check_1d(xy[0]) | ||
y = _check_1d(xy[1]) | ||
else: | ||
x, y = index_of(xy[-1]) | ||
if self.axes.xaxis is not None: | ||
self.axes.xaxis.update_units(x) | ||
@@ -445,10 +486,10 @@ def _plot_args(self, tup, kwargs, return_kwargs=False): | ||
y = y[:, np.newaxis] | ||
if self.command == 'plot': | ||
make_artist = self._makeline | ||
else: | ||
kw['closed'] = kwargs.get('closed', True) | ||
make_artist = self._makefill | ||
ncx, ncy = x.shape[1], y.shape[1] | ||
if ncx > 1 and ncy > 1 and ncx != ncy: | ||
@@ -465,8 +506,8 @@ def _plot_args(self, tup, kwargs, return_kwargs=False): | ||
else: | ||
labels = [label] * n_datasets | ||
result = (make_artist(x[:, j % ncx], y[:, j % ncy], kw, | ||
{**kwargs, 'label': label}) | ||
for j, label in enumerate(labels)) | ||
if return_kwargs: | ||