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

Skip to content

Commit 060d299

Browse files
authored
Merge pull request #14695 from anntzer/simplifications
Various small simplifications
2 parents 9e7a235 + 5d40a71 commit 060d299

File tree

7 files changed

+25
-42
lines changed

7 files changed

+25
-42
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,16 +2734,13 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
27342734
raise TypeError('stem expected between 1 and 5 positional '
27352735
'arguments, got {}'.format(args))
27362736

2737-
y = np.asarray(args[0])
2738-
args = args[1:]
2739-
2740-
# Try a second one
2741-
if not args:
2737+
if len(args) == 1:
2738+
y, = args
27422739
x = np.arange(len(y))
2740+
args = ()
27432741
else:
2744-
x = y
2745-
y = np.asarray(args[0], dtype=float)
2746-
args = args[1:]
2742+
x, y, *args = args
2743+
27472744
self._process_unit_info(xdata=x, ydata=y)
27482745
x = self.convert_xunits(x)
27492746
y = self.convert_yunits(y)
@@ -5056,6 +5053,7 @@ def fill(self, *args, data=None, **kwargs):
50565053
"""
50575054
# For compatibility(!), get aliases from Line2D rather than Patch.
50585055
kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D)
5056+
# _get_patches_for_fill returns a generator, convert it to a list.
50595057
patches = [*self._get_patches_for_fill(*args, data=data, **kwargs)]
50605058
for poly in patches:
50615059
self.add_patch(poly)

lib/matplotlib/axes/_base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,8 +1265,8 @@ def set_aspect(self, aspect, adjustable=None, anchor=None, share=False):
12651265
'on 3D axes')
12661266

12671267
if share:
1268-
axes = set(self._shared_x_axes.get_siblings(self)
1269-
+ self._shared_y_axes.get_siblings(self))
1268+
axes = {*self._shared_x_axes.get_siblings(self),
1269+
*self._shared_y_axes.get_siblings(self)}
12701270
else:
12711271
axes = [self]
12721272

@@ -1317,8 +1317,8 @@ def set_adjustable(self, adjustable, share=False):
13171317
"""
13181318
cbook._check_in_list(["box", "datalim"], adjustable=adjustable)
13191319
if share:
1320-
axes = set(self._shared_x_axes.get_siblings(self)
1321-
+ self._shared_y_axes.get_siblings(self))
1320+
axes = {*self._shared_x_axes.get_siblings(self),
1321+
*self._shared_y_axes.get_siblings(self)}
13221322
else:
13231323
axes = [self]
13241324
for ax in axes:
@@ -1385,8 +1385,8 @@ def set_anchor(self, anchor, share=False):
13851385
raise ValueError('argument must be among %s' %
13861386
', '.join(mtransforms.Bbox.coefs))
13871387
if share:
1388-
axes = set(self._shared_x_axes.get_siblings(self)
1389-
+ self._shared_y_axes.get_siblings(self))
1388+
axes = {*self._shared_x_axes.get_siblings(self),
1389+
*self._shared_y_axes.get_siblings(self)}
13901390
else:
13911391
axes = [self]
13921392
for ax in axes:

lib/matplotlib/backends/backend_ps.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -849,11 +849,7 @@ def _print_ps(self, outfile, format, *args,
849849
if papertype is None:
850850
papertype = rcParams['ps.papersize']
851851
papertype = papertype.lower()
852-
if papertype == 'auto':
853-
pass
854-
elif papertype not in papersize:
855-
raise RuntimeError('%s is not a valid papertype. Use one of %s' %
856-
(papertype, ', '.join(papersize)))
852+
cbook._check_in_list(['auto', *papersize], papertype=papertype)
857853

858854
orientation = orientation.lower()
859855
cbook._check_in_list(['landscape', 'portrait'],

lib/matplotlib/projections/polar.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,23 +136,19 @@ def __str__(self):
136136

137137
def transform_non_affine(self, xy):
138138
# docstring inherited
139-
x = xy[:, 0:1]
140-
y = xy[:, 1:]
139+
x, y = xy.T
141140
r = np.hypot(x, y)
142141
theta = (np.arctan2(y, x) + 2 * np.pi) % (2 * np.pi)
143-
144142
# PolarAxes does not use the theta transforms here, but apply them for
145143
# backwards-compatibility if not being used by it.
146144
if self._apply_theta_transforms and self._axis is not None:
147145
theta -= self._axis.get_theta_offset()
148146
theta *= self._axis.get_theta_direction()
149147
theta %= 2 * np.pi
150-
151148
if self._use_rmin and self._axis is not None:
152149
r += self._axis.get_rorigin()
153150
r *= self._axis.get_rsign()
154-
155-
return np.concatenate((theta, r), 1)
151+
return np.column_stack([theta, r])
156152

157153
def inverted(self):
158154
# docstring inherited

lib/matplotlib/tests/test_backend_cairo.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import os
44
import tempfile
55
import warnings
6-
import xml.parsers.expat
76

87
import pytest
98

lib/matplotlib/tri/triangulation.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,9 @@ def get_from_args_and_kwargs(*args, **kwargs):
134134
the possible args and kwargs.
135135
"""
136136
if isinstance(args[0], Triangulation):
137-
triangulation = args[0]
138-
args = args[1:]
137+
triangulation, *args = args
139138
else:
140-
x = args[0]
141-
y = args[1]
142-
args = args[2:] # Consumed first two args.
139+
x, y, *args = args
143140

144141
# Check triangles in kwargs then args.
145142
triangles = kwargs.pop('triangles', None)

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,8 +1512,7 @@ def plot(self, xs, ys, *args, zdir='z', **kwargs):
15121512
# args[0] is a string matches the behavior of 2D `plot` (via
15131513
# `_process_plot_var_args`).
15141514
if args and not isinstance(args[0], str):
1515-
zs = args[0]
1516-
args = args[1:]
1515+
zs, *args = args
15171516
if 'zs' in kwargs:
15181517
raise TypeError("plot() for multiple values for argument 'z'")
15191518
else:
@@ -1971,12 +1970,12 @@ def plot_trisurf(self, *args, color=None, norm=None, vmin=None, vmax=None,
19711970

19721971
tri, args, kwargs = \
19731972
Triangulation.get_from_args_and_kwargs(*args, **kwargs)
1974-
if 'Z' in kwargs:
1975-
z = np.asarray(kwargs.pop('Z'))
1976-
else:
1977-
z = np.asarray(args[0])
1973+
try:
1974+
z = kwargs.pop('Z')
1975+
except KeyError:
19781976
# We do this so Z doesn't get passed as an arg to PolyCollection
1979-
args = args[1:]
1977+
z, *args = args
1978+
z = np.asarray(z)
19801979

19811980
triangles = tri.get_masked_triangles()
19821981
xt = tri.x[triangles]
@@ -2154,9 +2153,8 @@ def tricontour(self, *args,
21542153
if 'Z' in kwargs:
21552154
Z = kwargs.pop('Z')
21562155
else:
2157-
Z = args[0]
21582156
# We do this so Z doesn't get passed as an arg to Axes.tricontour
2159-
args = args[1:]
2157+
Z, *args = args
21602158

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

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

0 commit comments

Comments
 (0)