8000 Remove extraneous if 1 statements in demo_axisline_style.py · matplotlib/matplotlib@02abf44 · GitHub
[go: up one dir, main page]

Skip to content

Commit 02abf44

Browse files
abhinuvpitaleQuLogic
authored andcommitted
Remove extraneous if 1 statements in demo_axisline_style.py
* change proposed in issue #12191 removed the confusing if 1: as propsed in #12191 * change requested in #12191 * added main() to resolve comments from #12191 * update #12191 * flake-8 corrections #12191 * update ```plt.show``` for #12191 * flake8 update #12191
1 parent 5d2d37e commit 02abf44

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

examples/axisartist/demo_axisline_style.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@
1010
import matplotlib.pyplot as plt
1111
import numpy as np
1212

13-
if 1:
14-
fig = plt.figure()
15-
ax = SubplotZero(fig, 111)
16-
fig.add_subplot(ax)
1713

18-
for direction in ["xzero", "yzero"]:
19-
# adds arrows at the ends of each axis
20-
ax.axis[direction].set_axisline_style("-|>")
14+
fig = plt.figure()
15+
ax = SubplotZero(fig, 111)
16+
fig.add_subplot(ax)
2117

22-
# adds X and Y-axis from the origin
23-
ax.axis[direction].set_visible(True)
18+
for direction in ["xzero" 8000 , "yzero"]:
19+
# adds arrows at the ends of each axis
20+
ax.axis[direction].set_axisline_style("-|>")
2421

25-
for direction in ["left", "right", "bottom", "top"]:
26-
# hides borders
27-
ax.axis[direction].set_visible(False)
22+
# adds X and Y-axis from the origin
23+
ax.axis[direction].set_visible(True)
2824

29-
x = np.linspace(-0.5, 1., 100)
30-
ax.plot(x, np.sin(x*np.pi))
25+
for direction in ["left", "right", "bottom", "top"]:
26+
# hides borders
27+
ax.axis[direction].set_visible(False)
3128

32-
plt.show()
29+
x = np.linspace(-0.5, 1., 100)
30+
ax.plot(x, np.sin(x*np.pi))
31+
32+
plt.show()

examples/event_handling/pick_event_demo.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ def pick_handler(event):
7474
import numpy as np
7575
from numpy.random import rand
7676

77-
if 1: # simple picking, lines, rectangles and text
77+
78+
def pick_simple():
79+
# simple picking, lines, rectangles and text
7880
fig, (ax1, ax2) = plt.subplots(2, 1)
7981
ax1.set_title('click on points, rectangles or text', picker=True)
8082
ax1.set_ylabel('ylabel', picker=True, bbox=dict(facecolor='red'))
@@ -101,7 +103,9 @@ def onpick1(event):
101103

102104
fig.canvas.mpl_connect('pick_event', onpick1)
103105

104-
if 1: # picking with a custom hit test function
106+
107+
def pick_custom_hit():
108+
# picking with a custom hit test function
105109
# you can define custom pickers by setting picker to a callable
106110
# function. The function has the signature
107111
#
@@ -142,7 +146,8 @@ def onpick2(event):
142146
fig.canvas.mpl_connect('pick_event', onpick2)
143147

144148

145-
if 1: # picking on a scatter plot (matplotlib.collections.RegularPolyCollection)
149+
def pick_scatter_plot():
150+
# picking on a scatter plot (matplotlib.collections.RegularPolyCollection)
146151

147152
x, y, c, s = rand(4, 100)
148153

@@ -155,7 +160,9 @@ def onpick3(event):
155160
#fig.savefig('pscoll.eps')
156161
fig.canvas.mpl_connect('pick_event', onpick3)
157162

158-
if 1: # picking images (matplotlib.image.AxesImage)
163+
164+
def pick_image():
165+
# picking images (matplotlib.image.AxesImage)
159166
fig, ax = plt.subplots()
160167
im1 = ax.imshow(rand(10, 5), extent=(1, 2, 1, 2), picker=True)
161168
im2 = ax.imshow(rand(5, 10), extent=(3, 4, 1, 2), picker=True)
@@ -173,4 +180,9 @@ def onpick4(event):
173180
fig.canvas.mpl_connect('pick_event', onpick4)
174181

175182

176-
plt.show()
183+
if __name__ == '__main__':
184+
pick_simple()
185+
pick_custom_hit()
186+
pick_scatter_plot()
187+
pick_image()
188+
plt.show()

0 commit comments

Comments
 (0)
0