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

Skip to content

Commit 0922790

Browse files
anntzertimhoffm
authored andcommitted
Small cleanups. (#13136)
((mostly (extra) parentheses)).
1 parent bcae715 commit 0922790

12 files changed

Lines changed: 30 additions & 36 deletions

File tree

examples/color/named_colors.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ def plot_colortable(colors, title, sort_colors=True, emptycols=0):
2727
topmargin = 40
2828

2929
# Sort colors by hue, saturation, value and name.
30-
by_hsv = ((tuple(mcolors.rgb_to_hsv(mcolors.to_rgba(color)[:3])), name)
31-
for name, color in colors.items())
3230
if sort_colors is True:
33-
by_hsv = sorted(by_hsv)
34-
names = [name for hsv, name in by_hsv]
31+
by_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgb(color))),
32+
name)
33+
for name, color in colors.items())
34+
names = [name for hsv, name in by_hsv]
35+
else:
36+
names = list(colors)
3537

3638
n = len(names)
3739
ncols = 4 - emptycols

examples/images_contours_and_fields/tricontour_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
y = np.degrees(xy[:, 1])
7676
x0 = -5
7777
y0 = 52
78-
z = np.exp(-0.01 * ((x - x0) * (x - x0) + (y - y0) * (y - y0)))
78+
z = np.exp(-0.01 * ((x - x0) ** 2 + (y - y0) ** 2))
7979

8080
triangles = np.asarray([
8181
[67, 66, 1], [65, 2, 66], [ 1, 66, 2], [64, 2, 65], [63, 3, 64],

examples/text_labels_and_annotations/legend_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def create_artists(self, legend, orig_handle,
133133
leglines = []
134134
# divide the vertical space where the lines will go
135135
# into equal parts based on the number of lines
136-
ydata = ((height) / (numlines + 1)) * np.ones(xdata.shape, float)
136+
ydata = np.full_like(xdata, height / (numlines + 1))
137137
# for each line, create the line at the proper location
138138
# and set the dash pattern
139139
for i in range(numlines):

lib/matplotlib/_layoutbox.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def constrain_geometry(self, left, bottom, right, top, strength='strong'):
234234
self.bottom == bottom,
235235
self.top == top]
236236
for c in hc:
237-
self.solver.addConstraint((c | strength))
237+
self.solver.addConstraint(c | strength)
238238
# self.solver.updateVariables()
239239

240240
def constrain_same(self, other, strength='strong'):
@@ -246,7 +246,7 @@ def constrain_same(self, other, strength='strong'):
246246
self.bottom == other.bottom,
247247
self.top == other.top]
248248
for c in hc:
249-
self.solver.addConstraint((c | strength))
249+
self.solver.addConstraint(c | strength)
250250

251251
def constrain_left_margin(self, margin, strength='strong'):
252252
c = (self.left == self.parent.left + margin)
@@ -467,7 +467,7 @@ def layout_from_subplotspec(self, subspec,
467467
self.width == parent.width * width,
468468
self.height == parent.height * height]
469469
for c in cs:
470-
self.solver.addConstraint((c | 'required'))
470+
self.solver.addConstraint(c | 'required')
471471

472472
return lb
473473

lib/matplotlib/colors.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,18 +1641,15 @@ def shade(self, data, cmap, norm=None, blend_mode='overlay', vmin=None,
16411641
def shade_rgb(self, rgb, elevation, fraction=1., blend_mode='hsv',
16421642
vert_exag=1, dx=1, dy=1, **kwargs):
16431643
"""
1644-
Take the input RGB array (ny*nx*3) adjust their color values
1645-
to given the impression of a shaded relief map with a
1646-
specified light source using the elevation (ny*nx).
1647-
A new RGB array ((ny*nx*3)) is returned.
1644+
Use this light source to adjust the colors of the *rgb* input array to
1645+
give the impression of a shaded relief map with the given `elevation`.
16481646
16491647
Parameters
16501648
----------
16511649
rgb : array-like
1652-
An MxNx3 RGB array, assumed to be in the range of 0 to 1.
1650+
An (M, N, 3) RGB array, assumed to be in the range of 0 to 1.
16531651
elevation : array-like
1654-
A 2d array (or equivalent) of the height values used to generate a
1655-
shaded map.
1652+
An (M, N) array of the height values used to generate a shaded map.
16561653
fraction : number
16571654
Increases or decreases the contrast of the hillshade. Values
16581655
greater than one will cause intermediate values to move closer to
@@ -1684,7 +1681,7 @@ def shade_rgb(self, rgb, elevation, fraction=1., blend_mode='hsv',
16841681
Returns
16851682
-------
16861683
shaded_rgb : ndarray
1687-
An MxNx3 array of floats ranging between 0-1.
1684+
An (m, n, 3) array of floats ranging between 0-1.
16881685
"""
16891686
# Calculate the "hillshade" intensity.
16901687
intensity = self.hillshade(elevation, vert_exag, dx, dy, fraction)

lib/matplotlib/figure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ def get_constrained_layout_pads(self, relative=False):
584584
wspace = self._constrained_layout_pads['wspace']
585585
hspace = self._constrained_layout_pads['hspace']
586586

587-
if relative and ((w_pad is not None) or (h_pad is not None)):
587+
if relative and (w_pad is not None or h_pad is not None):
588588
renderer0 = layoutbox.get_renderer(self)
589589
dpi = renderer0.dpi
590590
w_pad = w_pad * dpi / renderer0.width

lib/matplotlib/streamplot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ def __init__(self, grid, mask):
272272

273273
def grid2mask(self, xi, yi):
274274
"""Return nearest space in mask-coords from given grid-coords."""
275-
return (int((xi * self.x_grid2mask) + 0.5),
276-
int((yi * self.y_grid2mask) + 0.5))
275+
return (int(xi * self.x_grid2mask + 0.5),
276+
int(yi * self.y_grid2mask + 0.5))
277277

278278
def mask2grid(self, xm, ym):
279279
return xm * self.x_mask2grid, ym * self.y_mask2grid

lib/matplotlib/tests/test_colorbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def test_colorbar_axes_kw():
397397
# test fix for #8493: This does only test, that axes-related keywords pass
398398
# and do not raise an exception.
399399
plt.figure()
400-
plt.imshow(([[1, 2], [3, 4]]))
400+
plt.imshow([[1, 2], [3, 4]])
401401
plt.colorbar(orientation='horizontal', fraction=0.2, pad=0.2, shrink=0.5,
402402
aspect=10, anchor=(0., 0.), panchor=(0., 1.))
403403

lib/matplotlib/tests/test_transforms.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def test_contains_branch(self):
296296
assert r1.contains_branch(r2)
297297
assert r1.contains_branch(self.ta1)
298298
assert not r1.contains_branch(self.ta2)
299-
assert not r1.contains_branch((self.ta2 + self.ta2))
299+
assert not r1.contains_branch(self.ta2 + self.ta2)
300300

301301
assert r1 == r2
302302

@@ -309,10 +309,10 @@ def test_contains_branch(self):
309309
assert not self.stack2_subset.contains_branch(self.stack1)
310310
assert not self.stack2_subset.contains_branch(self.stack2)
311311

312-
assert self.stack1.contains_branch((self.ta2 + self.ta3))
313-
assert self.stack2.contains_branch((self.ta2 + self.ta3))
312+
assert self.stack1.contains_branch(self.ta2 + self.ta3)
313+
assert self.stack2.contains_branch(self.ta2 + self.ta3)
314314

315-
assert not self.stack1.contains_branch((self.tn1 + self.ta2))
315+
assert not self.stack1.contains_branch(self.tn1 + self.ta2)
316316

317317
def test_affine_simplification(self):
318318
# tests that a transform stack only calls as much is absolutely

lib/matplotlib/tests/test_triangulation.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,13 @@ def test_delaunay():
5656

5757

5858
def test_delaunay_duplicate_points():
59-
# x[duplicate] == x[duplicate_of]
60-
# y[duplicate] == y[duplicate_of]
6159
npoints = 10
6260
duplicate = 7
6361
duplicate_of = 3
6462

6563
np.random.seed(23)
66-
x = np.random.random((npoints))
67-
y = np.random.random((npoints))
64+
x = np.random.random(npoints)
65+
y = np.random.random(npoints)
6866
x[duplicate] = x[duplicate_of]
6967
y[duplicate] = y[duplicate_of]
7068

0 commit comments

Comments
 (0)