Skip to content

Commit af8a720

Browse files
authored
Merge pull request #13097 from anntzer/tupleless
Replace 1-tuples by scalars where possible.
2 parents f9c06a4 + 2527617 commit af8a720

File tree

14 files changed

+46
-58
lines changed

14 files changed

+46
-58
lines changed

examples/images_contours_and_fields/contour_label_demo.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,8 @@
3636

3737
class nf(float):
3838
def __repr__(self):
39-
str = '%.1f' % (self.__float__(),)
40-
if str[-1] == '0':
41-
return '%.0f' % self.__float__()
42-
else:
43-
return '%.1f' % self.__float__()
39+
s = f'{self:.1f}'
40+
return f'{self:.0f}' if s[-1] == '0' else s
4441

4542

4643
# Basic contour plot

examples/misc/transoffset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
x=0.05, y=0.10, units='inches')
3939

4040
for x, y in zip(xs, ys):
41-
plt.plot((x,), (y,), 'ro')
41+
plt.plot(x, y, 'ro')
4242
plt.text(x, y, '%d, %d' % (int(x), int(y)), transform=trans_offset)
4343

4444

@@ -49,7 +49,7 @@
4949
y=6, units='dots')
5050

5151
for x, y in zip(xs, ys):
52-
plt.polar((x,), (y,), 'ro')
52+
plt.polar(x, y, 'ro')
5353
plt.text(x, y, '%d, %d' % (int(x), int(y)),
5454
transform=trans_offset,
5555
horizontalalignment='center',

examples/mplot3d/lorenz_attractor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def lorenz(x, y, z, s=10, r=28, b=2.667):
3838
num_steps = 10000
3939

4040
# Need one more for the initial values
41-
xs = np.empty((num_steps + 1,))
42-
ys = np.empty((num_steps + 1,))
43-
zs = np.empty((num_steps + 1,))
41+
xs = np.empty(num_steps + 1)
42+
ys = np.empty(num_steps + 1)
43+
zs = np.empty(num_steps + 1)
4444

4545
# Set initial values
4646
xs[0], ys[0], zs[0] = (0., 1., 1.05)

lib/matplotlib/colorbar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ def _process_values(self, b=None):
790790
if self.values is not None:
791791
self._values = np.array(self.values)
792792
if self.boundaries is None:
793-
b = np.zeros(len(self.values) + 1, 'd')
793+
b = np.zeros(len(self.values) + 1)
794794
b[1:-1] = 0.5 * (self._values[:-1] - self._values[1:])
795795
b[0] = 2.0 * b[1] - b[2]
796796
b[-1] = 2.0 * b[-2] - b[-3]
@@ -802,7 +802,7 @@ def _process_values(self, b=None):
802802
# make reasonable ones based on cmap and norm.
803803
if isinstance(self.norm, colors.NoNorm):
804804
b = self._uniform_y(self.cmap.N + 1) * self.cmap.N - 0.5
805-
v = np.zeros((len(b) - 1,), dtype=np.int16)
805+
v = np.zeros(len(b) - 1, dtype=np.int16)
806806
v[self._inside] = np.arange(self.cmap.N, dtype=np.int16)
807807
if self._extend_lower():
808808
v[0] = -1
@@ -818,7 +818,7 @@ def _process_values(self, b=None):
818818
if self._extend_upper():
819819
b = b + [b[-1] + 1]
820820
b = np.array(b)
821-
v = np.zeros((len(b) - 1,), dtype=float)
821+
v = np.zeros(len(b) - 1)
822822
bi = self.norm.boundaries
823823
v[self._inside] = 0.5 * (bi[:-1] + bi[1:])
824824
if self._extend_lower():

lib/matplotlib/colors.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,14 +412,15 @@ def makeMappingArray(N, data, gamma=1.0):
412412
raise ValueError("data mapping points must have x in increasing order")
413413
# begin generation of lookup table
414414
x = x * (N - 1)
415-
lut = np.zeros((N,), float)
416415
xind = (N - 1) * np.linspace(0, 1, N) ** gamma
417416
ind = np.searchsorted(x, xind)[1:-1]
418417

419418
distance = (xind[1:-1] - x[ind - 1]) / (x[ind] - x[ind - 1])
420-
lut[1:-1] = distance * (y0[ind] - y1[ind - 1]) + y1[ind - 1]
421-
lut[0] = y1[0]
422-
lut[-1] = y0[-1]
419+
lut = np.concatenate([
420+
[y1[0]],
421+
distance * (y0[ind] - y1[ind - 1]) + y1[ind - 1],
422+
[y0[-1]],
423+
])
423424
# ensure that the lut is confined to values between 0 and 1 by clipping it
424425
return np.clip(lut, 0.0, 1.0)
425426

@@ -543,8 +544,7 @@ def __call__(self, X, alpha=None, bytes=False):
543544
# If the bad value is set to have a color, then we
544545
# override its alpha just as for any other value.
545546

546-
rgba = np.empty(shape=xa.shape + (4,), dtype=lut.dtype)
547-
lut.take(xa, axis=0, mode='clip', out=rgba)
547+
rgba = lut.take(xa, axis=0, mode='clip')
548548
if vtype == 'scalar':
549549
rgba = tuple(rgba[0, :])
550550
return rgba

lib/matplotlib/hatch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def get_path(hatchpattern, density=6):
201201
return Path(np.empty((0, 2)))
202202

203203
vertices = np.empty((num_vertices, 2))
204-
codes = np.empty((num_vertices,), np.uint8)
204+
codes = np.empty(num_vertices, Path.code_type)
205205

206206
cursor = 0
207207
for pattern in patterns:

lib/matplotlib/mlab.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,12 @@ def _spectral_helper(x, y=None, NFFT=None, Fs=None, detrend_func=None,
516516
# zero pad x and y up to NFFT if they are shorter than NFFT
517517
if len(x) < NFFT:
518518
n = len(x)
519-
x = np.resize(x, (NFFT,))
519+
x = np.resize(x, NFFT)
520520
x[n:] = 0
521521

522522
if not same_data and len(y) < NFFT:
523523
n = len(y)
524-
y = np.resize(y, (NFFT,))
524+
y = np.resize(y, NFFT)
525525
y[n:] = 0
526526

527527
if pad_to is None:
@@ -1598,7 +1598,7 @@ def evaluate(self, points):
15981598
raise ValueError("points have dimension {}, dataset has dimension "
15991599
"{}".format(dim, self.dim))
16001600

1601-
result = np.zeros((num_m,), dtype=float)
1601+
result = np.zeros(num_m)
16021602

16031603
if num_m >= self.num_dp:
16041604
# there are more points than data, so loop over data

lib/matplotlib/projections/polar.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,12 +1122,10 @@ def set_theta_direction(self, direction):
11221122
Theta increases in the counterclockwise direction
11231123
"""
11241124
mtx = self._direction.get_matrix()
1125-
if direction in ('clockwise',):
1125+
if direction in ('clockwise', -1):
11261126
mtx[0, 0] = -1
1127-
elif direction in ('counterclockwise', 'anticlockwise'):
1127+
elif direction in ('counterclockwise', 'anticlockwise', 1):
11281128
mtx[0, 0] = 1
1129-
elif direction in (1, -1):
1130-
mtx[0, 0] = direction
11311129
else:
11321130
raise ValueError(
11331131
"direction must be 1, -1, clockwise or counterclockwise")

lib/matplotlib/quiver.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,8 @@ def _init(self):
306306
# Hack: save and restore the Umask
307307
_mask = self.Q.Umask
308308
self.Q.Umask = ma.nomask
309-
self.verts = self.Q._make_verts(np.array([self.U]),
310-
np.zeros((1,)),
311-
self.angle)
309+
self.verts = self.Q._make_verts(
310+
np.array([self.U]), np.zeros(1), self.angle)
312311
self.Q.Umask = _mask
313312
self.Q.pivot = _pivot
314313
kw = self.Q.polykw

lib/matplotlib/tests/test_axes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,13 +630,13 @@ def test_const_xy():
630630
fig = plt.figure()
631631

632632
plt.subplot(311)
633-
plt.plot(np.arange(10), np.ones((10,)))
633+
plt.plot(np.arange(10), np.ones(10))
634634

635635
plt.subplot(312)
636-
plt.plot(np.ones((10,)), np.arange(10))
636+
plt.plot(np.ones(10), np.arange(10))
637637

638638
plt.subplot(313)
639-
plt.plot(np.ones((10,)), np.ones((10,)), 'o')
639+
plt.plot(np.ones(10), np.ones(10), 'o')
640640

641641

642642
@image_comparison(baseline_images=['polar_wrap_180', 'polar_wrap_360'],
@@ -5198,7 +5198,7 @@ def test_violin_point_mass():
51985198

51995199

52005200
def generate_errorbar_inputs():
5201-
base_xy = cycler('x', [np.arange(5)]) + cycler('y', [np.ones((5, ))])
5201+
base_xy = cycler('x', [np.arange(5)]) + cycler('y', [np.ones(5)])
52025202
err_cycler = cycler('err', [1,
52035203
[1, 1, 1, 1, 1],
52045204
[[1, 1, 1, 1, 1],

0 commit comments

Comments
 (0)