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

Skip to content

Commit cab5dcc

Browse files
authored
Code style cleanup (#16044)
Code style cleanup
2 parents 3261ed2 + fca65ed commit cab5dcc

26 files changed

+44
-48
lines changed

examples/images_contours_and_fields/contourf_log.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# A low hump with a spike coming out.
2121
# Needs to have z/colour axis on a log scale so we see both hump and spike.
2222
# linear scale only shows the spike.
23-
Z1 = np.exp(-(X)**2 - (Y)**2)
23+
Z1 = np.exp(-X**2 - Y**2)
2424
Z2 = np.exp(-(X * 10)**2 - (Y * 10)**2)
2525
z = Z1 + 50 * Z2
2626

examples/images_contours_and_fields/pcolor_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
# A low hump with a spike coming out.
9090
# Needs to have z/colour axis on a log scale so we see both hump and spike.
9191
# linear scale only shows the spike.
92-
Z1 = np.exp(-(X)**2 - (Y)**2)
92+
Z1 = np.exp(-X**2 - Y**2)
9393
Z2 = np.exp(-(X * 10)**2 - (Y * 10)**2)
9494
Z = Z1 + 50 * Z2
9595

examples/text_labels_and_annotations/mathtext_examples.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def doall():
7272
plt.gca().set_yticklabels("", visible=False)
7373

7474
# Gap between lines in axes coords
75-
line_axesfrac = (1. / (n_lines))
75+
line_axesfrac = 1 / n_lines
7676

7777
# Plotting header demonstration formula
7878
full_demo = mathext_demos[0]
@@ -82,7 +82,7 @@ def doall():
8282

8383
# Plotting features demonstration formulae
8484
for i_line in range(1, n_lines):
85-
baseline = 1 - (i_line) * line_axesfrac
85+
baseline = 1 - i_line * line_axesfrac
8686
baseline_next = baseline - line_axesfrac
8787
title = mathtext_titles[i_line] + ":"
8888
fill_color = ['white', mpl_blue_rvb][i_line % 2]

examples/userdemo/colormap_normalizations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
# z/colour axis on a log scale so we see both hump and spike. linear
2222
# scale only shows the spike.
2323

24-
Z1 = np.exp(-(X)**2 - (Y)**2)
24+
Z1 = np.exp(-X**2 - Y**2)
2525
Z2 = np.exp(-(X * 10)**2 - (Y * 10)**2)
2626
Z = Z1 + 50 * Z2
2727

@@ -41,7 +41,7 @@
4141
# sine wave in Y. We can remove the power law using a PowerNorm.
4242

4343
X, Y = np.mgrid[0:3:complex(0, N), 0:2:complex(0, N)]
44-
Z1 = (1 + np.sin(Y * 10.)) * X**(2.)
44+
Z1 = (1 + np.sin(Y * 10.)) * X**2
4545

4646
fig, ax = plt.subplots(2, 1)
4747

examples/userdemo/colormap_normalizations_power.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
sine wave in Y. We can remove the power law using a PowerNorm.
1919
'''
2020
X, Y = np.mgrid[0:3:complex(0, N), 0:2:complex(0, N)]
21-
Z1 = (1 + np.sin(Y * 10.)) * X**(2.)
21+
Z1 = (1 + np.sin(Y * 10.)) * X**2
2222

2323
fig, ax = plt.subplots(2, 1)
2424

lib/matplotlib/_layoutbox.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,15 @@ def _is_subplotspec_layoutbox(self):
350350
Helper to check if this layoutbox is the layoutbox of a
351351
subplotspec
352352
'''
353-
name = (self.name).split('.')[-1]
353+
name = self.name.split('.')[-1]
354354
return name[:2] == 'ss'
355355

356356
def _is_gridspec_layoutbox(self):
357357
'''
358358
Helper to check if this layoutbox is the layoutbox of a
359359
gridspec
360360
'''
361-
name = (self.name).split('.')[-1]
361+
name = self.name.split('.')[-1]
362362
return name[:8] == 'gridspec'
363363

364364
def find_child_subplots(self):

lib/matplotlib/animation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def correct_roundoff(x, dpi, n):
8989

9090
wnew = int(w * dpi / n) * n / dpi
9191
hnew = int(h * dpi / n) * n / dpi
92-
return (correct_roundoff(wnew, dpi, n), correct_roundoff(hnew, dpi, n))
92+
return correct_roundoff(wnew, dpi, n), correct_roundoff(hnew, dpi, n)
9393

9494

9595
# A registry for available MovieWriter classes

lib/matplotlib/artist.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ def axes(self, new_axes):
200200
self._axes = new_axes
201201
if new_axes is not None and new_axes is not self:
202202
self.stale_callback = _stale_axes_callback
203-
return new_axes
204203

205204
@property
206205
def stale(self):

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ def invert(x):
610610
secax.set_xlabel('Period [s]')
611611
plt.show()
612612
"""
613-
if (location in ['top', 'bottom'] or isinstance(location, Number)):
613+
if location in ['top', 'bottom'] or isinstance(location, Number):
614614
secondary_ax = SecondaryAxis(self, 'x', location, functions,
615615
**kwargs)
616616
self.add_child_axes(secondary_ax)

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,7 +2523,7 @@ def tol(x): return 1e-5 * abs(x) + 1e-8
25232523
'minposy', self.yaxis, self._ymargin, y_stickies, self.set_ybound)
25242524

25252525
def _get_axis_list(self):
2526-
return (self.xaxis, self.yaxis)
2526+
return self.xaxis, self.yaxis
25272527

25282528
def _get_axis_map(self):
25292529
"""
@@ -3966,7 +3966,7 @@ def _get_view(self):
39663966
"""
39673967
xmin, xmax = self.get_xlim()
39683968
ymin, ymax = self.get_ylim()
3969-
return (xmin, xmax, ymin, ymax)
3969+
return xmin, xmax, ymin, ymax
39703970

39713971
def _set_view(self, view):
39723972
"""

lib/matplotlib/backend_bases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2876,7 +2876,7 @@ def press_zoom(self, event):
28762876
"""Callback for mouse button press in zoom to rect mode."""
28772877
# If we're already in the middle of a zoom, pressing another
28782878
# button works to "cancel"
2879-
if self._ids_zoom != []:
2879+
if self._ids_zoom:
28802880
for zoom_id in self._ids_zoom:
28812881
self.canvas.mpl_disconnect(zoom_id)
28822882
self.release(event)

lib/matplotlib/backend_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ def _press(self, event):
868868

869869
# If we're already in the middle of a zoom, pressing another
870870
# button works to "cancel"
871-
if self._ids_zoom != []:
871+
if self._ids_zoom:
872872
self._cancel_action()
873873

874874
if event.button == 1:

lib/matplotlib/backends/backend_svg.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,15 +1193,13 @@ def print_svg(self, filename, *args, **kwargs):
11931193
fh = TextIOWrapper(fh, 'utf-8')
11941194
detach = True
11951195

1196-
result = self._print_svg(filename, fh, **kwargs)
1196+
self._print_svg(filename, fh, **kwargs)
11971197

11981198
# Detach underlying stream from wrapper so that it remains open in
11991199
# the caller.
12001200
if detach:
12011201
fh.detach()
12021202

1203-
return result
1204-
12051203
def print_svgz(self, filename, *args, **kwargs):
12061204
with cbook.open_file_cm(filename, "wb") as fh, \
12071205
gzip.GzipFile(mode='w', fileobj=fh) as gzipwriter:

lib/matplotlib/contour.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ def _process_args(self, *args, **kwargs):
14291429
if (t != self.ax.transData and
14301430
any(t.contains_branch_seperately(self.ax.transData))):
14311431
trans_to_data = t - self.ax.transData
1432-
pts = (np.vstack([x.flat, y.flat]).T)
1432+
pts = np.vstack([x.flat, y.flat]).T
14331433
transformed_pts = trans_to_data.transform(pts)
14341434
x = transformed_pts[..., 0]
14351435
y = transformed_pts[..., 1]

lib/matplotlib/dates.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -889,16 +889,15 @@ def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'):
889889
self._tz = tz
890890
self.defaultfmt = defaultfmt
891891
self._formatter = DateFormatter(self.defaultfmt, tz)
892-
self.scaled = {DAYS_PER_YEAR: rcParams['date.autoformatter.year'],
893-
DAYS_PER_MONTH: rcParams['date.autoformatter.month'],
894-
1.0: rcParams['date.autoformatter.day'],
895-
1. / HOURS_PER_DAY: rcParams['date.autoformatter.hour'],
896-
1. / (MINUTES_PER_DAY):
897-
rcParams['date.autoformatter.minute'],
898-
1. / (SEC_PER_DAY):
899-
rcParams['date.autoformatter.second'],
900-
1. / (MUSECONDS_PER_DAY):
901-
rcParams['date.autoformatter.microsecond']}
892+
self.scaled = {
893+
DAYS_PER_YEAR: rcParams['date.autoformatter.year'],
894+
DAYS_PER_MONTH: rcParams['date.autoformatter.month'],
895+
1: rcParams['date.autoformatter.day'],
896+
1 / HOURS_PER_DAY: rcParams['date.autoformatter.hour'],
897+
1 / MINUTES_PER_DAY: rcParams['date.autoformatter.minute'],
898+
1 / SEC_PER_DAY: rcParams['date.autoformatter.second'],
899+
1 / MUSECONDS_PER_DAY: rcParams['date.autoformatter.microsecond']
900+
}
902901

903902
def _set_locator(self, locator):
904903
self._locator = locator

lib/matplotlib/hatch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def __init__(self, hatch, density):
9595
self.num_vertices = 0
9696
else:
9797
self.num_shapes = ((self.num_rows // 2 + 1) * (self.num_rows + 1) +
98-
(self.num_rows // 2) * (self.num_rows))
98+
(self.num_rows // 2) * self.num_rows)
9999
self.num_vertices = (self.num_shapes *
100100
len(self.shape_vertices) *
101101
(1 if self.filled else 2))

lib/matplotlib/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ def set_data(self, A):
683683
raise TypeError("Image data of dtype {} cannot be converted to "
684684
"float".format(self._A.dtype))
685685

686-
if (self._A.ndim == 3 and self._A.shape[-1] == 1):
686+
if self._A.ndim == 3 and self._A.shape[-1] == 1:
687687
# If just one dimension assume scalar and apply colormap
688688
self._A = self._A[:, :, 0]
689689

lib/matplotlib/legend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ def _get_anchored_bbox(self, loc, bbox, parentbbox, renderer):
10481048
c = anchor_coefs[loc]
10491049

10501050
fontsize = renderer.points_to_pixels(self._fontsize)
1051-
container = parentbbox.padded(-(self.borderaxespad) * fontsize)
1051+
container = parentbbox.padded(-self.borderaxespad * fontsize)
10521052
anchored_box = bbox.anchored(c, container=container)
10531053
return anchored_box.x0, anchored_box.y0
10541054

lib/matplotlib/mathtext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ def _get_font(self, font):
568568

569569
def _get_offset(self, font, glyph, fontsize, dpi):
570570
if font.postscript_name == 'Cmex10':
571-
return ((glyph.height/64.0/2.0) + (fontsize/3.0 * dpi/72.0))
571+
return (glyph.height / 64 / 2) + (fontsize/3 * dpi/72)
572572
return 0.
573573

574574
def _get_info(self, fontname, font_class, sym, fontsize, dpi, math=True):
@@ -2025,7 +2025,7 @@ def __init__(self, c, height, depth, state, always=False, factor=None):
20252025
shift = 0
20262026
if state.font != 0:
20272027
if factor is None:
2028-
factor = (target_total) / (char.height + char.depth)
2028+
factor = target_total / (char.height + char.depth)
20292029
state.fontsize *= factor
20302030
char = Char(sym, state)
20312031

lib/matplotlib/tests/test_figure.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def test_align_labels():
4343

4444
for i in range(3):
4545
ax = fig.add_subplot(gs[2, i])
46-
ax.set_xlabel('XLabel2 %d' % (i))
47-
ax.set_ylabel('YLabel2 %d' % (i))
46+
ax.set_xlabel(f'XLabel2 {i}')
47+
ax.set_ylabel(f'YLabel2 {i}')
4848

4949
if i == 2:
5050
ax.plot(np.arange(0, 1e4, 10))

lib/matplotlib/tests/test_triangulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ def meshgrid_triangles(n):
941941
tri = []
942942
for i in range(n-1):
943943
for j in range(n-1):
944-
a = i + j*(n)
944+
a = i + j*n
945945
b = (i+1) + j*n
946946
c = i + (j+1)*n
947947
d = (i+1) + (j+1)*n

lib/matplotlib/ticker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,15 +1982,15 @@ def le(self, x):
19821982
'Return the largest n: n*step <= x.'
19831983
d, m = divmod(x, self.step)
19841984
if self.closeto(m / self.step, 1):
1985-
return (d + 1)
1985+
return d + 1
19861986
return d
19871987

19881988
def ge(self, x):
19891989
'Return the smallest n: n*step >= x.'
19901990
d, m = divmod(x, self.step)
19911991
if self.closeto(m / self.step, 0):
19921992
return d
1993-
return (d + 1)
1993+
return d + 1
19941994

19951995

19961996
class MaxNLocator(Locator):

lib/matplotlib/tri/triinterpolate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ def compute_geom_weights(self):
11251125
weights = np.zeros([np.size(self._triangles, 0), 3])
11261126
tris_pts = self._tris_pts
11271127
for ipt in range(3):
1128-
p0 = tris_pts[:, (ipt) % 3, :]
1128+
p0 = tris_pts[:, ipt % 3, :]
11291129
p1 = tris_pts[:, (ipt+1) % 3, :]
11301130
p2 = tris_pts[:, (ipt-1) % 3, :]
11311131
alpha1 = np.arctan2(p1[:, 1]-p0[:, 1], p1[:, 0]-p0[:, 0])

lib/mpl_toolkits/axisartist/axis_artist.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def draw(self, renderer):
334334
text_ref_angle = self._get_text_ref_angle()
335335
offset_ref_angle = self._get_offset_ref_angle()
336336

337-
theta = (offset_ref_angle)/180.*np.pi
337+
theta = np.deg2rad(offset_ref_angle)
338338
dd = self._get_offset_radius()
339339
dx, dy = dd * np.cos(theta), dd * np.sin(theta)
340340
offset_tr.translate(dx, dy)
@@ -357,7 +357,7 @@ def get_window_extent(self, renderer):
357357
text_ref_angle = self._get_text_ref_angle()
358358
offset_ref_angle = self._get_offset_ref_angle()
359359

360-
theta = (offset_ref_angle)/180.*np.pi
360+
theta = np.deg2rad(offset_ref_angle)
361361
dd = self._get_offset_radius()
362362
dx, dy = dd * np.cos(theta), dd * np.sin(theta)
363363
offset_tr.translate(dx, dy)
@@ -722,7 +722,7 @@ def LABELPAD(self):
722722

723723
@LABELPAD.setter
724724
def LABELPAD(self, v):
725-
return self.label.set_pad(v)
725+
self.label.set_pad(v)
726726

727727
def __init__(self, axes,
728728
helper,

lib/mpl_toolkits/mplot3d/axis3d.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,15 +389,15 @@ def d_interval(self):
389389

390390
@d_interval.setter
391391
def d_interval(self, minmax):
392-
return self.set_data_interval(*minmax)
392+
self.set_data_interval(*minmax)
393393

394394
@property
395395
def v_interval(self):
396396
return self.get_view_interval()
397397

398398
@d_interval.setter
399399
def v_interval(self, minmax):
400-
return self.set_view_interval(*minmax)
400+
self.set_view_interval(*minmax)
401401

402402

403403
# Use classes to look at different data limits

tutorials/colors/colormapnorms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
# A low hump with a spike coming out of the top right. Needs to have
5555
# z/colour axis on a log scale so we see both hump and spike. linear
5656
# scale only shows the spike.
57-
Z1 = np.exp(-(X)**2 - (Y)**2)
57+
Z1 = np.exp(-X**2 - Y**2)
5858
Z2 = np.exp(-(X * 10)**2 - (Y * 10)**2)
5959
Z = Z1 + 50 * Z2
6060

@@ -126,7 +126,7 @@
126126

127127
N = 100
128128
X, Y = np.mgrid[0:3:complex(0, N), 0:2:complex(0, N)]
129-
Z1 = (1 + np.sin(Y * 10.)) * X**(2.)
129+
Z1 = (1 + np.sin(Y * 10.)) * X**2
130130

131131
fig, ax = plt.subplots(2, 1)
132132

0 commit comments

Comments
 (0)