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

Skip to content

Commit b7cc09e

Browse files
committed
Small cleanups.
Use enumerate(); use decorators.
1 parent 83cb3ef commit b7cc09e

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
@@ -899,12 +899,10 @@ def _rc_params_in_file(fname, fail_on_error=False):
899899
Unlike `rc_params_from_file`, the configuration class only contains the
900900
parameters specified in the file (i.e. default values are not filled in).
901901
"""
902-
cnt = 0
903902
rc_temp = {}
904903
with _open_file_or_url(fname) as fd:
905904
try:
906-
for line in fd:
907-
cnt += 1
905+
for cnt, line in enumerate(fd, 1):
908906
strippedline = line.split('#', 1)[0].strip()
909907
if not strippedline:
910908
continue

lib/matplotlib/axes/_axes.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2968,7 +2968,6 @@ def get_next_color():
29682968
slices = []
29692969
autotexts = []
29702970

2971-
i = 0
29722971
for frac, label, expl in zip(x, labels, explode):
29732972
x, y = center
29742973
theta2 = (theta1 + frac) if counterclock else (theta1 - frac)
@@ -3032,7 +3031,6 @@ def get_next_color():
30323031
autotexts.append(t)
30333032

30343033
theta1 = theta2
3035-
i += 1
30363034

30373035
if not frame:
30383036
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
@@ -5111,11 +5111,9 @@ def test_rc_grid():
51115111
}
51125112
dict_list = [rc_dict0, rc_dict1, rc_dict2]
51135113

5114-
i = 1
5115-
for rc_dict in dict_list:
5114+
for i, rc_dict in enumerate(dict_list, 1):
51165115
with matplotlib.rc_context(rc_dict):
51175116
fig.add_subplot(3, 1, i)
5118-
i += 1
51195117

51205118

51215119
def test_rc_tick():

lib/matplotlib/tests/test_triangulation.py

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

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

lib/matplotlib/transforms.py

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

266266
if DEBUG:
267+
@staticmethod
267268
def _check(points):
268269
if isinstance(points, np.ma.MaskedArray):
269270
cbook._warn_external("Bbox bounds are a masked array.")
270271
points = np.asarray(points)
271272
if (points[1, 0] - points[0, 0] == 0 or
272273
points[1, 1] - points[0, 1] == 0):
273274
cbook._warn_external("Singular Bbox.")
274-
_check = staticmethod(_check)
275275

276276
def frozen(self):
277277
return Bbox(self.get_points().copy())

lib/matplotlib/widgets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ def _keypress(self, event):
809809
if self.capturekeystrokes:
810810
key = event.key
811811

812-
if(len(key) == 1):
812+
if len(key) == 1:
813813
self.text = (self.text[:self.cursor_index] + key +
814814
self.text[self.cursor_index:])
815815
self.cursor_index += 1

0 commit comments

Comments
 (0)