Skip to content

Commit 5805fc3

Browse files
committed
Merge pull request matplotlib#3515 from thisch/examples_pep8_e111_e113
examples: fix pep8 error classes E111 and E113
2 parents c791f9e + cb81f1a commit 5805fc3

File tree

11 files changed

+479
-483
lines changed

11 files changed

+479
-483
lines changed

examples/event_handling/data_browser.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ def onpress(self, event):
2828

2929
def onpick(self, event):
3030

31-
if event.artist!=line: return True
31+
if event.artist!=line: return True
3232

33-
N = len(event.ind)
34-
if not N: return True
33+
N = len(event.ind)
34+
if not N: return True
3535

36-
# the click locations
37-
x = event.mouseevent.xdata
38-
y = event.mouseevent.ydata
36+
# the click locations
37+
x = event.mouseevent.xdata
38+
y = event.mouseevent.ydata
3939

40-
distances = np.hypot(x-xs[event.ind], y-ys[event.ind])
41-
indmin = distances.argmin()
42-
dataind = event.ind[indmin]
40+
distances = np.hypot(x-xs[event.ind], y-ys[event.ind])
41+
indmin = distances.argmin()
42+
dataind = event.ind[indmin]
4343

44-
self.lastind = dataind
45-
self.update()
44+
self.lastind = dataind
45+
self.update()
4646

4747
def update(self):
4848
if self.lastind is None: return

examples/event_handling/looking_glass.py

+29-29
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,35 @@
1313

1414

1515
class EventHandler:
16-
def __init__(self):
17-
fig.canvas.mpl_connect('button_press_event', self.onpress)
18-
fig.canvas.mpl_connect('button_release_event', self.onrelease)
19-
fig.canvas.mpl_connect('motion_notify_event', self.onmove)
20-
self.x0, self.y0 = circ.center
21-
self.pressevent = None
22-
23-
def onpress(self, event):
24-
if event.inaxes!=ax:
25-
return
26-
27-
if not circ.contains(event)[0]:
28-
return
29-
30-
self.pressevent = event
31-
32-
def onrelease(self, event):
33-
self.pressevent = None
34-
self.x0, self.y0 = circ.center
35-
36-
def onmove(self, event):
37-
if self.pressevent is None or event.inaxes!=self.pressevent.inaxes:
38-
return
39-
40-
dx = event.xdata - self.pressevent.xdata
41-
dy = event.ydata - self.pressevent.ydata
42-
circ.center = self.x0 + dx, self.y0 + dy
43-
line.set_clip_path(circ)
44-
fig.canvas.draw()
16+
def __init__(self):
17+
fig.canvas.mpl_connect('button_press_event', self.onpress)
18+
fig.canvas.mpl_connect('button_release_event', self.onrelease)
19+
fig.canvas.mpl_connect('motion_notify_event', self.onmove)
20+
self.x0, self.y0 = circ.center
21+
self.pressevent = None
22+
23+
def onpress(self, event):
24+
if event.inaxes!=ax:
25+
return
26+
27+
if not circ.contains(event)[0]:
28+
return
29+
30+
self.pressevent = event
31+
32+
def onrelease(self, event):
33+
self.pressevent = None
34+
self.x0, self.y0 = circ.center
35+
36+
def onmove(self, event):
37+
if self.pressevent is None or event.inaxes!=self.pressevent.inaxes:
38+
return
39+
40+
dx = event.xdata - self.pressevent.xdata
41+
dy = event.ydata - self.pressevent.ydata
42+
circ.center = self.x0 + dx, self.y0 + dy
43+
line.set_clip_path(circ)
44+
fig.canvas.draw()
4545

4646
handler = EventHandler()
4747
plt.show()

examples/misc/rc_traits.py

+94-97
Original file line numberDiff line numberDiff line change
@@ -34,63 +34,63 @@
3434

3535

3636
def hex2color(s):
37-
"Convert hex string (like html uses, eg, #efefef) to a r,g,b tuple"
38-
return tuple([int(n, 16)/255.0 for n in (s[1:3], s[3:5], s[5:7])])
37+
"Convert hex string (like html uses, eg, #efefef) to a r,g,b tuple"
38+
return tuple([int(n, 16)/255.0 for n in (s[1:3], s[3:5], s[5:7])])
3939

4040

4141
class RGBA(traits.HasTraits):
42-
# r,g,b,a in the range 0-1 with default color 0,0,0,1 (black)
43-
r = traits.Range(0., 1., 0.)
44-
g = traits.Range(0., 1., 0.)
45-
b = traits.Range(0., 1., 0.)
46-
a = traits.Range(0., 1., 1.)
42+
# r,g,b,a in the range 0-1 with default color 0,0,0,1 (black)
43+
r = traits.Range(0., 1., 0.)
44+
g = traits.Range(0., 1., 0.)
45+
b = traits.Range(0., 1., 0.)
46+
a = traits.Range(0., 1., 1.)
4747

48-
def __init__(self, r=0., g=0., b=0., a=1.):
49-
self.r = r
50-
self.g = g
51-
self.b = b
52-
self.a = a
48+
def __init__(self, r=0., g=0., b=0., a=1.):
49+
self.r = r
50+
self.g = g
51+
self.b = b
52+
self.a = a
5353

54-
def __repr__(self):
55-
return 'r,g,b,a = (%1.2f, %1.2f, %1.2f, %1.2f)'%\
56-
(self.r, self.g, self.b, self.a)
54+
def __repr__(self):
55+
return 'r,g,b,a = (%1.2f, %1.2f, %1.2f, %1.2f)'%\
56+
(self.r, self.g, self.b, self.a)
5757

5858

5959
def tuple_to_rgba(ob, name, val):
60-
tup = [float(x) for x in val]
61-
if len(tup)==3:
62-
r,g,b = tup
63-
return RGBA(r,g,b)
64-
elif len(tup)==4:
65-
r,g,b,a = tup
66-
return RGBA(r,g,b,a)
67-
else:
68-
raise ValueError
60+
tup = [float(x) for x in val]
61+
if len(tup)==3:
62+
r,g,b = tup
63+
return RGBA(r,g,b)
64+
elif len(tup)==4:
65+
r,g,b,a = tup
66+
return RGBA(r,g,b,a)
67+
else:
68+
raise ValueError
6969
tuple_to_rgba.info = 'a RGB or RGBA tuple of floats'
7070

7171

7272
def hex_to_rgba(ob, name, val):
73-
rgx = re.compile('^#[0-9A-Fa-f]{6}$')
74-
75-
if not is_string_like(val):
76-
raise TypeError
77-
if rgx.match(val) is None:
78-
raise ValueError
79-
r,g,b = hex2color(val)
80-
return RGBA(r,g,b,1.0)
73+
rgx = re.compile('^#[0-9A-Fa-f]{6}$')
74+
75+
if not is_string_like(val):
76+
raise TypeError
77+
if rgx.match(val) is None:
78+
raise ValueError
79+
r,g,b = hex2color(val)
80+
return RGBA(r,g,b,1.0)
8181
hex_to_rgba.info = 'a hex color string'
8282

8383

8484
def colorname_to_rgba(ob, name, val):
85-
hex = colors[val.lower()]
86-
r,g,b = hex2color(hex)
87-
return RGBA(r,g,b,1.0)
85+
hex = colors[val.lower()]
86+
r,g,b = hex2color(hex)
87+
return RGBA(r,g,b,1.0)
8888
colorname_to_rgba.info = 'a named color'
8989

9090

9191
def float_to_rgba(ob, name, val):
92-
val = float(val)
93-
return RGBA(val, val, val, 1.)
92+
val = float(val)
93+
return RGBA(val, val, val, 1.)
9494
float_to_rgba.info = 'a grayscale intensity'
9595

9696

@@ -99,12 +99,9 @@ def float_to_rgba(ob, name, val):
9999

100100

101101
def file_exists(ob, name, val):
102-
fh = file(val, 'r')
103-
return val
102+
fh = file(val, 'r')
103+
return val
104104

105-
106-
def path_exists(ob, name, val):
107-
os.path.exists(val)
108105
linestyles = ('-', '--', '-.', ':', 'steps', 'None')
109106
TICKLEFT, TICKRIGHT, TICKUP, TICKDOWN = range(4)
110107
linemarkers = (None, '.', ',', 'o', '^', 'v', '<', '>', 's',
@@ -119,23 +116,23 @@ def path_exists(ob, name, val):
119116

120117

121118
class LineRC(traits.HasTraits):
122-
linewidth = traits.Float(0.5)
123-
linestyle = traits.Trait(*linestyles)
124-
color = Color
125-
marker = traits.Trait(*linemarkers)
126-
markerfacecolor = Color
127-
markeredgecolor = Color
128-
markeredgewidth = traits.Float(0.5)
129-
markersize = traits.Float(6)
130-
antialiased = flexible_true_trait
131-
data_clipping = flexible_false_trait
119+
linewidth = traits.Float(0.5)
120+
linestyle = traits.Trait(*linestyles)
121+
color = Color
122+
marker = traits.Trait(*linemarkers)
123+
markerfacecolor = Color
124+
markeredgecolor = Color
125+
markeredgewidth = traits.Float(0.5)
126+
markersize = traits.Float(6)
127+
antialiased = flexible_true_trait
128+
data_clipping = flexible_false_trait
132129

133130

134131
class PatchRC(traits.HasTraits):
135-
linewidth = traits.Float(1.0)
136-
facecolor = Color
137-
edgecolor = Color
138-
antialiased = flexible_true_trait
132+
linewidth = traits.Float(1.0)
133+
facecolor = Color
134+
edgecolor = Color
135+
antialiased = flexible_true_trait
139136

140137
timezones = 'UTC', 'US/Central', 'ES/Eastern' # fixme: and many more
141138
backends = ('GTKAgg', 'Cairo', 'GDK', 'GTK', 'Agg',
@@ -144,51 +141,51 @@ class PatchRC(traits.HasTraits):
144141

145142

146143
class RC(traits.HasTraits):
147-
backend = traits.Trait(*backends)
148-
interactive = flexible_false_trait
149-
toolbar = traits.Trait('toolbar2', 'classic', None)
150-
timezone = traits.Trait(*timezones)
151-
lines = traits.Trait(LineRC())
152-
patch = traits.Trait(PatchRC())
144+
backend = traits.Trait(*backends)
145+
interactive = flexible_false_trait
146+
toolbar = traits.Trait('toolbar2', 'classic', None)
147+
timezone = traits.Trait(*timezones)
148+
lines = traits.Trait(LineRC())
149+
patch = traits.Trait(PatchRC())
153150

154151
rc = RC()
155152
rc.lines.color = 'r'
156153
if doprint:
157-
print('RC')
158-
rc.print_traits()
159-
print('RC lines')
160-
rc.lines.print_traits()
161-
print('RC patches')
162-
rc.patch.print_traits()
154+
print('RC')
155+
rc.print_traits()
156+
print('RC lines')
157+
rc.lines.print_traits()
158+
print('RC patches')
159+
rc.patch.print_traits()
163160

164161

165162
class Patch(Artist, traits.HasTraits):
166-
linewidth = traits.Float(0.5)
167-
facecolor = Color
168-
fc = facecolor
169-
edgecolor = Color
170-
fill = flexible_true_trait
171-
172-
def __init__(self,
173-
edgecolor=None,
174-
facecolor=None,
175-
linewidth=None,
176-
antialiased = None,
177-
fill=1,
178-
**kwargs
179-
):
180-
Artist.__init__(self)
181-
182-
if edgecolor is None: edgecolor = rc.patch.edgecolor
183-
if facecolor is None: facecolor = rc.patch.facecolor
184-
if linewidth is None: linewidth = rc.patch.linewidth
185-
if antialiased is None: antialiased = rc.patch.antialiased
186-
187-
self.edgecolor = edgecolor
188-
self.facecolor = facecolor
189-
self.linewidth = linewidth
190-
self.antialiased = antialiased
191-
self.fill = fill
163+
linewidth = traits.Float(0.5)
164+
facecolor = Color
165+
fc = facecolor
166+
edgecolor = Color
167+
fill = flexible_true_trait
168+
169+
def __init__(self,
170+
edgecolor=None,
171+
facecolor=None,
172+
linewidth=None,
173+
antialiased = None,
174+
fill=1,
175+
**kwargs
176+
):
177+
Artist.__init__(self)
178+
179+
if edgecolor is None: edgecolor = rc.patch.edgecolor
180+
if facecolor is None: facecolor = rc.patch.facecolor
181+
if linewidth is None: linewidth = rc.patch.linewidth
182+
if antialiased is None: antialiased = rc.patch.antialiased
183+
184+
self.edgecolor = edgecolor
185+
self.facecolor = facecolor
186+
self.linewidth = linewidth
187+
self.antialiased = antialiased
188+
self.fill = fill
192189

193190

194191
p = Patch()
@@ -202,6 +199,6 @@ def __init__(self,
202199
if p.fill_: print('fill')
203200
else: print('no fill')
204201
if doprint:
205-
print()
206-
print('Patch')
207-
p.print_traits()
202+
print()
203+
print('Patch')
204+
p.print_traits()

examples/mplot3d/custom_shaded_3d_surface.py

-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,3 @@
2929
linewidth=0, antialiased=False, shade=False)
3030

3131
plt.show()
32-

0 commit comments

Comments
 (0)