Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4da5bc1

Browse filesBrowse files
committed
Simplify _process_plot_var_args.
- The unit handling at the top of `__call__` is duplicated with `Axes._process_unit_info`, so just use that. - The conditional call to `convert_xunits` in `_xy_from_xy` can be moved to `_makefill` (the only case where it's needed), and made non-conditional (if `x` is not unitized, `convert_xunits` will just return it as is). - The rest of `_xy_from_xy` can be inlined into its only call site (`_plot_args`) which also makes clear that the calls to `_check_1d` are redundant because the caller already calls `_check_1d` (possibly via `index_of`) immediately before.
1 parent db06a34 commit 4da5bc1
Copy full SHA for 4da5bc1

File tree

Expand file treeCollapse file tree

1 file changed

+22
-56
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+22
-56
lines changed

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+22-56Lines changed: 22 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,7 @@ def set_prop_cycle(self, *args, **kwargs):
151151
self._prop_keys = prop_cycler.keys
152152

153153
def __call__(self, *args, **kwargs):
154-
# Process units.
155-
if self.axes.xaxis is not None and self.axes.yaxis is not None:
156-
xunits = kwargs.pop('xunits', self.axes.xaxis.units)
157-
if self.axes.name == 'polar':
158-
xunits = kwargs.pop('thetaunits', xunits)
159-
if xunits != self.axes.xaxis.units:
160-
self.axes.xaxis.set_units(xunits)
161-
yunits = kwargs.pop('yunits', self.axes.yaxis.units)
162-
if self.axes.name == 'polar':
163-
yunits = kwargs.pop('runits', yunits)
164-
if yunits != self.axes.yaxis.units:
165-
self.axes.yaxis.set_units(yunits)
154+
self.axes._process_unit_info(kwargs=kwargs)
166155

167156
for pos_only in "xy":
168157
if pos_only in kwargs:
@@ -232,46 +221,6 @@ def get_next_color(self):
232221
return 'k'
233222
return next(self.prop_cycler)['color']
234223

235-
def _xy_from_xy(self, x, y):
236-
if self.axes.xaxis is not None and self.axes.yaxis is not None:
237-
bx = self.axes.xaxis.update_units(x)
238-
by = self.axes.yaxis.update_units(y)
239-
240-
if self.command != 'plot':
241-
# the Line2D class can handle unitized data, with
242-
# support for post hoc unit changes etc. Other mpl
243-
# artists, e.g., Polygon which _process_plot_var_args
244-
# also serves on calls to fill, cannot. So this is a
245-
# hack to say: if you are not "plot", which is
246-
# creating Line2D, then convert the data now to
247-
# floats. If you are plot, pass the raw data through
248-
# to Line2D which will handle the conversion. So
249-
# polygons will not support post hoc conversions of
250-
# the unit type since they are not storing the orig
251-
# data. Hopefully we can rationalize this at a later
252-
# date - JDH
253-
if bx:
254-
x = self.axes.convert_xunits(x)
255-
if by:
256-
y = self.axes.convert_yunits(y)
257-
258-
# like asanyarray, but converts scalar to array, and doesn't change
259-
# existing compatible sequences
260-
x = _check_1d(x)
261-
y = _check_1d(y)
262-
if x.shape[0] != y.shape[0]:
263-
raise ValueError("x and y must have same first dimension, but "
264-
"have shapes {} and {}".format(x.shape, y.shape))
265-
if x.ndim > 2 or y.ndim > 2:
266-
raise ValueError("x and y can be no greater than 2-D, but have "
267-
"shapes {} and {}".format(x.shape, y.shape))
268-
269-
if x.ndim == 1:
270-
x = x[:, np.newaxis]
271-
if y.ndim == 1:
272-
y = y[:, np.newaxis]
273-
return x, y
274-
275224
def _getdefaults(self, ignore, kw):
276225
"""
277226
If some keys in the property cycle (excluding those in the set
@@ -307,6 +256,10 @@ def _makeline(self, x, y, kw, kwargs):
307256
return seg
308257

309258
def _makefill(self, x, y, kw, kwargs):
259+
# Polygon doesn't directly support unitized inputs.
260+
x = self.axes.convert_xunits(x)
261+
y = self.axes.convert_yunits(y)
262+
310263
kw = kw.copy() # Don't modify the original kw.
311264
kwargs = kwargs.copy()
312265

@@ -364,9 +317,8 @@ def _plot_args(self, tup, kwargs):
364317
else:
365318
linestyle, marker, color = None, None, None
366319

367-
# Don't allow any None value; These will be up-converted
368-
# to one element array of None which causes problems
369-
# downstream.
320+
# Don't allow any None value; these would be up-converted to one
321+
# element array of None which causes problems downstream.
370322
if any(v is None for v in tup):
371323
raise ValueError("x, y, and format string must not be None")
372324

@@ -382,7 +334,21 @@ def _plot_args(self, tup, kwargs):
382334
else:
383335
x, y = index_of(tup[-1])
384336

385-
x, y = self._xy_from_xy(x, y)
337+
if self.axes.xaxis is not None:
338+
self.axes.xaxis.update_units(x)
339+
if self.axes.yaxis is not None:
340+
self.axes.yaxis.update_units(y)
341+
342+
if x.shape[0] != y.shape[0]:
343+
raise ValueError(f"x and y must have same first dimension, but "
344+
f"have shapes {x.shape} and {y.shape}")
345+
if x.ndim > 2 or y.ndim > 2:
346+
raise ValueError(f"x and y can be no greater than 2-D, but have "
347+
f"shapes {x.shape} and {y.shape}")
348+
if x.ndim == 1:
349+
x = x[:, np.newaxis]
350+
if y.ndim == 1:
351+
y = y[:, np.newaxis]
386352

387353
if self.command == 'plot':
388354
func = self._makeline

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.