Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Various small simplifications #14695

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2734,16 +2734,13 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
raise TypeError('stem expected between 1 and 5 positional '
'arguments, got {}'.format(args))

y = np.asarray(args[0])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if you need this asarray bit? I guess it's covered by convert_xunits?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes; in fact this change means that stem now correctly handles units on y-data (whereas they would be previously dropped by the call to asarray). Not an intentional change though :)

args = args[1:]

# Try a second one
if not args:
if len(args) == 1:
y, = args
x = np.arange(len(y))
args = ()
else:
x = y
y = np.asarray(args[0], dtype=float)
args = args[1:]
x, y, *args = args

self._process_unit_info(xdata=x, ydata=y)
x = self.convert_xunits(x)
y = self.convert_yunits(y)
Expand Down Expand Up @@ -5056,6 +5053,7 @@ def fill(self, *args, data=None, **kwargs):
"""
# For compatibility(!), get aliases from Line2D rather than Patch.
kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D)
# _get_patches_for_fill returns a generator, convert it to a list.
patches = [*self._get_patches_for_fill(*args, data=data, **kwargs)]
for poly in patches:
self.add_patch(poly)
Expand Down
12 changes: 6 additions & 6 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1265,8 +1265,8 @@ def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
'on 3D axes')

if share:
axes = set(self._shared_x_axes.get_siblings(self)
+ self._shared_y_axes.get_siblings(self))
axes = {*self._shared_x_axes.get_siblings(self),
*self._shared_y_axes.get_siblings(self)}
else:
axes = [self]

Expand Down Expand Up @@ -1317,8 +1317,8 @@ def set_adjustable(self, adjustable, share=False):
"""
cbook._check_in_list(["box", "datalim"], adjustable=adjustable)
if share:
axes = set(self._shared_x_axes.get_siblings(self)
+ self._shared_y_axes.get_siblings(self))
axes = {*self._shared_x_axes.get_siblings(self),
*self._shared_y_axes.get_siblings(self)}
else:
axes = [self]
for ax in axes:
Expand Down Expand Up @@ -1385,8 +1385,8 @@ def set_anchor(self, anchor, share=False):
raise ValueError('argument must be among %s' %
', '.join(mtransforms.Bbox.coefs))
if share:
axes = set(self._shared_x_axes.get_siblings(self)
+ self._shared_y_axes.get_siblings(self))
axes = {*self._shared_x_axes.get_siblings(self),
*self._shared_y_axes.get_siblings(self)}
else:
axes = [self]
for ax in axes:
Expand Down
6 changes: 1 addition & 5 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,11 +849,7 @@ def _print_ps(self, outfile, format, *args,
if papertype is None:
papertype = rcParams['ps.papersize']
papertype = papertype.lower()
if papertype == 'auto':
pass
elif papertype not in papersize:
raise RuntimeError('%s is not a valid papertype. Use one of %s' %
(papertype, ', '.join(papersize)))
cbook._check_in_list(['auto', *papersize], papertype=papertype)

orientation = orientation.lower()
cbook._check_in_list(['landscape', 'portrait'],
Expand Down
8 changes: 2 additions & 6 deletions lib/matplotlib/projections/polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,19 @@ def __str__(self):

def transform_non_affine(self, xy):
# docstring inherited
x = xy[:, 0:1]
y = xy[:, 1:]
x, y = xy.T
r = np.hypot(x, y)
theta = (np.arctan2(y, x) + 2 * np.pi) % (2 * np.pi)

# PolarAxes does not use the theta transforms here, but apply them for
# backwards-compatibility if not being used by it.
if self._apply_theta_transforms and self._axis is not None:
theta -= self._axis.get_theta_offset()
theta *= self._axis.get_theta_direction()
theta %= 2 * np.pi

if self._use_rmin and self._axis is not None:
r += self._axis.get_rorigin()
r *= self._axis.get_rsign()

return np.concatenate((theta, r), 1)
return np.column_stack([theta, r])

def inverted(self):
# docstring inherited
Expand Down
1 change: 0 additions & 1 deletion lib/matplotlib/tests/test_backend_cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
import tempfile
import warnings
import xml.parsers.expat

import pytest

Expand Down
7 changes: 2 additions & 5 deletions lib/matplotlib/tri/triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,9 @@ def get_from_args_and_kwargs(*args, **kwargs):
the possible args and kwargs.
"""
if isinstance(args[0], Triangulation):
triangulation = args[0]
args = args[1:]
triangulation, *args = args
else:
x = args[0]
y = args[1]
args = args[2:] # Consumed first two args.
x, y, *args = args

# Check triangles in kwargs then args.
triangles = kwargs.pop('triangles', None)
Expand Down
19 changes: 8 additions & 11 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1514,8 +1514,7 @@ def plot(self, xs, ys, *args, zdir='z', **kwargs):
# args[0] is a string matches the behavior of 2D `plot` (via
# `_process_plot_var_args`).
if args and not isinstance(args[0], str):
zs = args[0]
args = args[1:]
zs, *args = args
if 'zs' in kwargs:
raise TypeError("plot() for multiple values for argument 'z'")
else:
Expand Down Expand Up @@ -1973,12 +1972,12 @@ def plot_trisurf(self, *args, color=None, norm=None, vmin=None, vmax=None,

tri, args, kwargs = \
Triangulation.get_from_args_and_kwargs(*args, **kwargs)
if 'Z' in kwargs:
z = np.asarray(kwargs.pop('Z'))
else:
z = np.asarray(args[0])
try:
z = kwargs.pop('Z')
except KeyError:
# We do this so Z doesn't get passed as an arg to PolyCollection
args = args[1:]
z, *args = args
z = np.asarray(z)

triangles = tri.get_masked_triangles()
xt = tri.x[triangles]
Expand Down Expand Up @@ -2156,9 +2155,8 @@ def tricontour(self, *args,
if 'Z' in kwargs:
Z = kwargs.pop('Z')
else:
Z = args[0]
# We do this so Z doesn't get passed as an arg to Axes.tricontour
args = args[1:]
Z, *args = args

jX, jY, jZ = art3d.rotate_axes(X, Y, Z, zdir)
tri = Triangulation(jX, jY, tri.triangles, tri.mask)
Expand Down Expand Up @@ -2246,9 +2244,8 @@ def tricontourf(self, *args, zdir='z', offset=None, **kwargs):
if 'Z' in kwargs:
Z = kwargs.pop('Z')
else:
Z = args[0]
# We do this so Z doesn't get passed as an arg to Axes.tricontourf
args = args[1:]
Z, *args = args

jX, jY, jZ = art3d.rotate_axes(X, Y, Z, zdir)
tri = Triangulation(jX, jY, tri.triangles, tri.mask)
Expand Down