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

Skip to content

Commit 812d2fc

Browse files
authored
Merge pull request #13701 from anntzer/clean
Small cleanups.
2 parents bbbc15a + b7cc09e commit 812d2fc

File tree

9 files changed

+12
-24
lines changed

9 files changed

+12
-24
lines changed

examples/animation/animate_decay.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
import matplotlib.animation as animation
1414

1515

16-
def data_gen(t=0):
17-
cnt = 0
18-
while cnt < 1000:
19-
cnt += 1
20-
t += 0.1
16+
def data_gen():
17+
for cnt in range(1000):
18+
t = cnt / 10
2119
yield t, np.sin(2*np.pi*t) * np.exp(-t/10.)
2220

2321

lib/matplotlib/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,12 +891,10 @@ def _rc_params_in_file(fname, fail_on_error=False):
891891
Unlike `rc_params_from_file`, the configuration class only contains the
892892
parameters specified in the file (i.e. default values are not filled in).
893893
"""
894-
cnt = 0
895894
rc_temp = {}
896895
with _open_file_or_url(fname) as fd:
897896
try:
898-
for line in fd:
899-
cnt += 1
897+
for cnt, line in enumerate(fd, 1):
900898
strippedline = line.split('#', 1)[0].strip()
901899
if not strippedline:
902900
continue

lib/matplotlib/axes/_axes.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2991,7 +2991,6 @@ def get_next_color():
29912991
slices = []
29922992
autotexts = []
29932993

2994-
i = 0
29952994
for frac, label, expl in zip(x, labels, explode):
29962995
x, y = center
29972996
theta2 = (theta1 + frac) if counterclock else (theta1 - frac)
@@ -3055,7 +3054,6 @@ def get_next_color():
30553054
autotexts.append(t)
30563055

30573056
theta1 = theta2
3058-
i += 1
30593057

30603058
if not frame:
30613059
self.set_frame_on(False)

lib/matplotlib/mathtext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,9 +1898,9 @@ def copy(self):
18981898
self.shrink,
18991899
self.shrink_order)
19001900

1901+
@classmethod
19011902
def factory(cls, glue_type):
19021903
return cls._types[glue_type]
1903-
factory = classmethod(factory)
19041904

19051905

19061906
GlueSpec._types = {
@@ -2101,13 +2101,13 @@ def __call__(self, ox, oy, box):
21012101
self.off_v = oy + box.height
21022102
self.hlist_out(box)
21032103

2104+
@staticmethod
21042105
def clamp(value):
21052106
if value < -1000000000.:
21062107
return -1000000000.
21072108
if value > 1000000000.:
21082109
return 1000000000.
21092110
return value
2110-
clamp = staticmethod(clamp)
21112111

21122112
def hlist_out(self, box):
21132113
cur_g = 0

lib/matplotlib/testing/jpl_units/UnitDbl.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ def type(self):
203203
"""Return the type of UnitDbl data."""
204204
return self._types[self._units]
205205

206+
@staticmethod
206207
def range(start, stop, step=None):
207208
"""Generate a range of UnitDbl objects.
208209
@@ -235,8 +236,6 @@ def range(start, stop, step=None):
235236

236237
return elems
237238

238-
range = staticmethod(range)
239-
240239
def checkUnits(self, units):
241240
"""Check to see if some units are valid.
242241

lib/matplotlib/tests/test_axes.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5065,11 +5065,9 @@ def test_rc_grid():
50655065
}
50665066
dict_list = [rc_dict0, rc_dict1, rc_dict2]
50675067

5068-
i = 1
5069-
for rc_dict in dict_list:
5068+
for i, rc_dict in enumerate(dict_list, 1):
50705069
with matplotlib.rc_context(rc_dict):
50715070
fig.add_subplot(3, 1, i)
5072-
i += 1
50735071

50745072

50755073
def test_rc_tick():

lib/matplotlib/tests/test_triangulation.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,8 @@ def tri_contains_point(xtri, ytri, xy):
134134
# triangulation contain the test point xy. Avoid calling with a point that
135135
# lies on or very near to an edge of any triangle in the triangulation.
136136
def tris_contain_point(triang, xy):
137-
count = 0
138-
for tri in triang.triangles:
139-
if tri_contains_point(triang.x[tri], triang.y[tri], xy):
140-
count += 1
141-
return count
137+
return sum(tri_contains_point(triang.x[tri], triang.y[tri], xy)
138+
for tri in triang.triangles)
142139

143140
# Using matplotlib.delaunay, an invalid triangulation is created with
144141
# overlapping triangles; qhull is OK.

lib/matplotlib/transforms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,14 @@ class BboxBase(TransformNode):
262262
is_affine = True
263263

264264
if DEBUG:
265+
@staticmethod
265266
def _check(points):
266267
if isinstance(points, np.ma.MaskedArray):
267268
cbook._warn_external("Bbox bounds are a masked array.")
268269
points = np.asarray(points)
269270
if (points[1, 0] - points[0, 0] == 0 or
270271
points[1, 1] - points[0, 1] == 0):
271272
cbook._warn_external("Singular Bbox.")
272-
_check = staticmethod(_check)
273273

274274
def frozen(self):
275275
return Bbox(self.get_points().copy())

lib/matplotlib/widgets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ def _keypress(self, event):
806806
if self.capturekeystrokes:
807807
key = event.key
808808

809-
if(len(key) == 1):
809+
if len(key) == 1:
810810
self.text = (self.text[:self.cursor_index] + key +
811811
self.text[self.cursor_index:])
812812
self.cursor_index += 1

0 commit comments

Comments
 (0)