Skip to content

Commit e4dc869

Browse files
committed
Fixed PEP8 coding style violations of "unit"folder
`pep8 unit/*.py --ignore=E501` tells us everything is ok. As part of http://24pullrequests.com
1 parent 8aed22d commit e4dc869

12 files changed

+219
-184
lines changed

unit/agg_memleak.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
"""
44

55
from __future__ import print_function
6-
import sys, time, os
6+
import os
77
from matplotlib.ft2font import FT2Font
88
from numpy.random import rand
99
from matplotlib.backend_bases import GraphicsContextBase
1010
from matplotlib.backends._backend_agg import RendererAgg
1111

12+
1213
def report_memory(i):
1314
pid = os.getpid()
1415
a2 = os.popen('ps -p %d -o rss,sz' % pid).readlines()
@@ -20,40 +21,41 @@ def report_memory(i):
2021
N = 200
2122
for i in range(N):
2223
gc = GraphicsContextBase()
23-
gc.set_clip_rectangle( [20,20,20,20] )
24-
o = RendererAgg(400,400, 72)
24+
gc.set_clip_rectangle([20, 20, 20, 20])
25+
o = RendererAgg(400, 400, 72)
2526

2627
for j in range(50):
27-
xs = [400*int(rand()) for k in range(8)]
28-
ys = [400*int(rand()) for k in range(8)]
29-
rgb = (1,0,0)
28+
xs = [400 * int(rand()) for k in range(8)]
29+
ys = [400 * int(rand()) for k in range(8)]
30+
rgb = (1, 0, 0)
3031
pnts = zip(xs, ys)
3132
o.draw_polygon(gc, rgb, pnts) # no such method??
3233
o.draw_polygon(gc, None, pnts)
3334

3435
for j in range(50):
35-
x = [400*int(rand()) for k in range(4)]
36-
y = [400*int(rand()) for k in range(4)]
37-
o.draw_lines( gc, x, y)
36+
x = [400 * int(rand()) for k in range(4)]
37+
y = [400 * int(rand()) for k in range(4)]
38+
o.draw_lines(gc, x, y)
3839

3940
for j in range(50):
40-
args = [400*int(rand()) for k in range(4)]
41-
rgb = (1,0,0)
41+
args = [400 * int(rand()) for k in range(4)]
42+
rgb = (1, 0, 0)
4243
o.draw_rectangle(gc, rgb, *args)
4344

44-
if 1: # add text
45+
if 1: # add text
4546
font = FT2Font(fname)
4647
font.clear()
4748
font.set_text('hi mom', 60)
4849
font.set_size(12, 72)
4950
o.draw_text_image(font.get_image(), 30, 40, gc)
5051

51-
o.write_png('aggtest%d.png'%i)
52+
o.write_png('aggtest%d.png' % i)
5253
val = report_memory(i)
53-
if i==1: start = val
54+
if i == 1:
55+
start = val
5456

5557
end = val
56-
print('Average memory consumed per loop: %1.4f\n' % ((end-start)/float(N)))
58+
print('Average memory consumed per loop: %1.4f\n' % ((end - start) / float(N)))
5759

5860
# w/o text and w/o write_png: Average memory consumed per loop: 0.02
5961
# w/o text and w/ write_png : Average memory consumed per loop: 0.3400

unit/compare_backend_driver_results.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import print_function
22
import sys
33

4+
45
def parse_results(filename):
56
results = {}
67
fd = open(filename, 'r')
@@ -22,11 +23,11 @@ def check_results_are_compatible(results_a, results_b):
2223
for section in results_a.keys():
2324
if not section in results_b:
2425
raise RuntimeError("Backend '%s' in first set, but not in second" % section)
25-
26+
2627
for section in results_b.keys():
2728
if not section in results_a:
2829
raise RuntimeError("Backend '%s' in second set, but not in first" % section)
29-
30+
3031

3132
def compare_results(results_a, results_b):
3233
check_results_are_compatible(results_a, results_b)

unit/ellipse_large.py

Lines changed: 57 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
# This example can be boiled down to a more simplistic example
3-
# to show the problem, but bu including the upper and lower
3+
# to show the problem, but including the upper and lower
44
# bound ellipses, it demonstrates how significant this error
55
# is to our plots.
66

@@ -14,129 +14,121 @@
1414
y = 6720.850
1515

1616
# get is the radius of a circle through this point
17-
r = math.sqrt( x*x+y*y )
17+
r = math.sqrt(x * x + y * y)
1818

1919
# show some comparative circles
2020
delta = 6
2121

2222

2323
##################################################
24-
def custom_ellipse( ax, x, y, major, minor, theta, numpoints = 750, **kwargs ):
25-
xs = []
26-
ys = []
27-
incr = 2.0*math.pi / numpoints
28-
incrTheta = 0.0
29-
while incrTheta <= (2.0*math.pi):
30-
a = major * math.cos( incrTheta )
31-
b = minor * math.sin( incrTheta )
32-
l = math.sqrt( ( a**2 ) + ( b**2 ) )
33-
phi = math.atan2( b, a )
34-
incrTheta += incr
35-
36-
xs.append( x + ( l * math.cos( theta + phi ) ) )
37-
ys.append( y + ( l * math.sin( theta + phi ) ) )
38-
# end while
39-
40-
incrTheta = 2.0*math.pi
41-
a = major * math.cos( incrTheta )
42-
b = minor * math.sin( incrTheta )
43-
l = sqrt( ( a**2 ) + ( b**2 ) )
44-
phi = math.atan2( b, a )
45-
xs.append( x + ( l * math.cos( theta + phi ) ) )
46-
ys.append( y + ( l * math.sin( theta + phi ) ) )
47-
48-
ellipseLine = ax.plot( xs, ys, **kwargs )
49-
50-
24+
def custom_ellipse(ax, x, y, major, minor, theta, numpoints=750, **kwargs):
25+
xs = []
26+
ys = []
27+
incr = 2.0 * math.pi / numpoints
28+
incrTheta = 0.0
29+
while incrTheta <= (2.0 * math.pi):
30+
a = major * math.cos(incrTheta)
31+
b = minor * math.sin(incrTheta)
32+
l = math.sqrt((a ** 2) + (b ** 2))
33+
phi = math.atan2(b, a)
34+
incrTheta += incr
35+
36+
xs.append(x + (l * math.cos(theta + phi)))
37+
ys.append(y + (l * math.sin(theta + phi)))
38+
# end while
39+
40+
incrTheta = 2.0 * math.pi
41+
a = major * math.cos(incrTheta)
42+
b = minor * math.sin(incrTheta)
43+
l = sqrt((a ** 2) + (b ** 2))
44+
phi = math.atan2(b, a)
45+
xs.append(x + (l * math.cos(theta + phi)))
46+
ys.append(y + (l * math.sin(theta + phi)))
47+
48+
ellipseLine = ax.plot(xs, ys, **kwargs)
5149

5250

5351
##################################################
5452
# make the axes
55-
ax1 = subplot( 311, aspect='equal' )
56-
ax1.set_aspect( 'equal', 'datalim' )
53+
ax1 = subplot(311, aspect='equal')
54+
ax1.set_aspect('equal', 'datalim')
5755

5856
# make the lower-bound ellipse
5957
diam = (r - delta) * 2.0
60-
lower_ellipse = Ellipse( (0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkgreen" )
61-
ax1.add_patch( lower_ellipse )
58+
lower_ellipse = Ellipse((0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkgreen")
59+
ax1.add_patch(lower_ellipse)
6260

6361
# make the target ellipse
6462
diam = r * 2.0
65-
target_ellipse = Ellipse( (0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkred" )
66-
ax1.add_patch( target_ellipse )
63+
target_ellipse = Ellipse((0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkred")
64+
ax1.add_patch(target_ellipse)
6765

6866
# make the upper-bound ellipse
6967
diam = (r + delta) * 2.0
70-
upper_ellipse = Ellipse( (0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkblue" )
71-
ax1.add_patch( upper_ellipse )
68+
upper_ellipse = Ellipse((0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkblue")
69+
ax1.add_patch(upper_ellipse)
7270

7371
# make the target
7472
diam = delta * 2.0
75-
target = Ellipse( (x, y), diam, diam, 0.0, fill=False, edgecolor="#DD1208" )
76-
ax1.add_patch( target )
73+
target = Ellipse((x, y), diam, diam, 0.0, fill=False, edgecolor="#DD1208")
74+
ax1.add_patch(target)
7775

7876
# give it a big marker
79-
ax1.plot( [x], [y], marker='x', linestyle='None', mfc='red', mec='red', markersize=10 )
77+
ax1.plot([x], [y], marker='x', linestyle='None', mfc='red', mec='red', markersize=10)
8078

8179
##################################################
8280
# make the axes
83-
ax = subplot( 312, aspect='equal' , sharex=ax1, sharey=ax1)
84-
ax.set_aspect( 'equal', 'datalim' )
81+
ax = subplot(312, aspect='equal', sharex=ax1, sharey=ax1)
82+
ax.set_aspect('equal', 'datalim')
8583

8684
# make the lower-bound arc
8785
diam = (r - delta) * 2.0
88-
lower_arc = Arc( (0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkgreen" )
89-
ax.add_patch( lower_arc )
86+
lower_arc = Arc((0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkgreen")
87+
ax.add_patch(lower_arc)
9088

9189
# make the target arc
9290
diam = r * 2.0
93-
target_arc = Arc( (0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkred" )
94-
ax.add_patch( target_arc )
91+
target_arc = Arc((0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkred")
92+
ax.add_patch(target_arc)
9593

9694
# make the upper-bound arc
9795
diam = (r + delta) * 2.0
98-
upper_arc = Arc( (0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkblue" )
99-
ax.add_patch( upper_arc )
96+
upper_arc = Arc((0.0, 0.0), diam, diam, 0.0, fill=False, edgecolor="darkblue")
97+
ax.add_patch(upper_arc)
10098

10199
# make the target
102100
diam = delta * 2.0
103-
target = Arc( (x, y), diam, diam, 0.0, fill=False, edgecolor="#DD1208" )
104-
ax.add_patch( target )
101+
target = Arc((x, y), diam, diam, 0.0, fill=False, edgecolor="#DD1208")
102+
ax.add_patch(target)
105103

106104
# give it a big marker
107-
ax.plot( [x], [y], marker='x', linestyle='None', mfc='red', mec='red', markersize=10 )
108-
109-
110-
111-
105+
ax.plot([x], [y], marker='x', linestyle='None', mfc='red', mec='red', markersize=10)
112106

113107
##################################################
114108
# now lets do the same thing again using a custom ellipse function
115109

116-
117-
118110
# make the axes
119-
ax = subplot( 313, aspect='equal', sharex=ax1, sharey=ax1 )
120-
ax.set_aspect( 'equal', 'datalim' )
111+
ax = subplot(313, aspect='equal', sharex=ax1, sharey=ax1)
112+
ax.set_aspect('equal', 'datalim')
121113

122114
# make the lower-bound ellipse
123-
custom_ellipse( ax, 0.0, 0.0, r-delta, r-delta, 0.0, color="darkgreen" )
115+
custom_ellipse(ax, 0.0, 0.0, r - delta, r - delta, 0.0, color="darkgreen")
124116

125117
# make the target ellipse
126-
custom_ellipse( ax, 0.0, 0.0, r, r, 0.0, color="darkred" )
118+
custom_ellipse(ax, 0.0, 0.0, r, r, 0.0, color="darkred")
127119

128120
# make the upper-bound ellipse
129-
custom_ellipse( ax, 0.0, 0.0, r+delta, r+delta, 0.0, color="darkblue" )
121+
custom_ellipse(ax, 0.0, 0.0, r + delta, r + delta, 0.0, color="darkblue")
130122

131123
# make the target
132-
custom_ellipse( ax, x, y, delta, delta, 0.0, color="#BB1208" )
124+
custom_ellipse(ax, x, y, delta, delta, 0.0, color="#BB1208")
133125

134126
# give it a big marker
135-
ax.plot( [x], [y], marker='x', linestyle='None', mfc='red', mec='red', markersize=10 )
127+
ax.plot([x], [y], marker='x', linestyle='None', mfc='red', mec='red', markersize=10)
136128

137129

138130
# give it a big marker
139-
ax.plot( [x], [y], marker='x', linestyle='None', mfc='red', mec='red', markersize=10 )
131+
ax.plot([x], [y], marker='x', linestyle='None', mfc='red', mec='red', markersize=10)
140132

141133
##################################################
142134
# lets zoom in to see the area of interest
@@ -146,5 +138,3 @@ def custom_ellipse( ax, x, y, major, minor, theta, numpoints = 750, **kwargs ):
146138

147139
savefig("ellipse")
148140
show()
149-
150-

unit/legend_unit.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33

44
Ntests = 3
55
t = np.arange(0.0, 1.0, 0.05)
6-
s = np.sin(2*np.pi*t)
6+
s = np.sin(2 * np.pi * t)
77

88
# scatter creates a RegPolyCollection
99
fig = figure()
1010
ax = fig.add_subplot(Ntests, 1, 1)
1111
N = 100
12-
x, y = 0.9*np.random.rand(2,N)
13-
area = np.pi*(10 * np.random.rand(N))**2 # 0 to 10 point radiuses
14-
ax.scatter(x,y,s=area, marker='^', c='r', label='scatter')
12+
x, y = 0.9 * np.random.rand(2, N)
13+
area = np.pi * (10 * np.random.rand(N)) ** 2 # 0 to 10 point radiuses
14+
ax.scatter(x, y, s=area, marker='^', c='r', label='scatter')
1515
ax.legend()
1616

1717
# vlines creates a LineCollection
1818
ax = fig.add_subplot(Ntests, 1, 2)
19-
ax.vlines(t, [0], np.sin(2*np.pi*t), label='vlines')
19+
ax.vlines(t, [0], np.sin(2 * np.pi * t), label='vlines')
2020
ax.legend()
2121

2222
# vlines creates a LineCollection

unit/longs_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
from __future__ import print_function
55

66
from pylab import *
7-
x = arange(1000) + 2**32
7+
x = arange(1000) + 2 ** 32
88

99
subplot(211)
10-
plot(x,x)
10+
plot(x, x)
1111

1212
subplot(212)
13-
loglog(x,x)
13+
loglog(x, x)
1414

1515
show()

unit/memleak_gui.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
1616
'''
1717
from __future__ import print_function
18-
import os, sys, time
1918
import gc
2019
from optparse import OptionParser
2120

@@ -52,7 +51,7 @@
5251

5352
print('# columns are: iteration, OS memory (k), number of python objects')
5453
print('#')
55-
for i in range(indEnd+1):
54+
for i in range(indEnd + 1):
5655

5756
fig = pylab.figure()
5857
fig.savefig('test') # This seems to just slow down the testing.
@@ -63,9 +62,9 @@
6362
if options.verbose:
6463
if i % 10 == 0:
6564
#print ("iter: %4d OS memory: %8d Python objects: %8d" %
66-
print ("%4d %8d %8d" %
67-
(i, val, len(gc.get_objects())))
68-
if i==indStart: start = val # wait a few cycles for memory usage to stabilize
65+
print("%4d %8d %8d" % (i, val, len(gc.get_objects())))
66+
if i == indStart:
67+
start = val # wait a few cycles for memory usage to stabilize
6968

7069
gc.collect()
7170
end = val
@@ -98,7 +97,7 @@
9897

9998
print('# Averaging over loops %d to %d' % (indStart, indEnd))
10099
print('# Memory went from %dk to %dk' % (start, end))
101-
print('# Average memory consumed per loop: %1.4fk bytes\n' % ((end-start)/float(indEnd-indStart)))
100+
print('# Average memory consumed per loop: %1.4fk bytes\n' % ((end - start) / float(indEnd - indStart)))
102101

103102
if options.cycles:
104103
cbook.print_cycles(gc.garbage)

0 commit comments

Comments
 (0)