diff --git a/examples/axisartist/demo_axisline_style.py b/examples/axisartist/demo_axisline_style.py index 0ddabcb15cb9..fc61375147e4 100644 --- a/examples/axisartist/demo_axisline_style.py +++ b/examples/axisartist/demo_axisline_style.py @@ -10,23 +10,23 @@ import matplotlib.pyplot as plt import numpy as np -if 1: - fig = plt.figure() - ax = SubplotZero(fig, 111) - fig.add_subplot(ax) - for direction in ["xzero", "yzero"]: - # adds arrows at the ends of each axis - ax.axis[direction].set_axisline_style("-|>") +fig = plt.figure() +ax = SubplotZero(fig, 111) +fig.add_subplot(ax) - # adds X and Y-axis from the origin - ax.axis[direction].set_visible(True) +for direction in ["xzero", "yzero"]: + # adds arrows at the ends of each axis + ax.axis[direction].set_axisline_style("-|>") - for direction in ["left", "right", "bottom", "top"]: - # hides borders - ax.axis[direction].set_visible(False) + # adds X and Y-axis from the origin + ax.axis[direction].set_visible(True) - x = np.linspace(-0.5, 1., 100) - ax.plot(x, np.sin(x*np.pi)) +for direction in ["left", "right", "bottom", "top"]: + # hides borders + ax.axis[direction].set_visible(False) - plt.show() +x = np.linspace(-0.5, 1., 100) +ax.plot(x, np.sin(x*np.pi)) + +plt.show() diff --git a/examples/event_handling/pick_event_demo.py b/examples/event_handling/pick_event_demo.py index 4f2a924e1d23..7198bff484a5 100644 --- a/examples/event_handling/pick_event_demo.py +++ b/examples/event_handling/pick_event_demo.py @@ -74,7 +74,9 @@ def pick_handler(event): import numpy as np from numpy.random import rand -if 1: # simple picking, lines, rectangles and text + +def pick_simple(): + # simple picking, lines, rectangles and text fig, (ax1, ax2) = plt.subplots(2, 1) ax1.set_title('click on points, rectangles or text', picker=True) ax1.set_ylabel('ylabel', picker=True, bbox=dict(facecolor='red')) @@ -101,7 +103,9 @@ def onpick1(event): fig.canvas.mpl_connect('pick_event', onpick1) -if 1: # picking with a custom hit test function + +def pick_custom_hit(): + # picking with a custom hit test function # you can define custom pickers by setting picker to a callable # function. The function has the signature # @@ -142,7 +146,8 @@ def onpick2(event): fig.canvas.mpl_connect('pick_event', onpick2) -if 1: # picking on a scatter plot (matplotlib.collections.RegularPolyCollection) +def pick_scatter_plot(): + # picking on a scatter plot (matplotlib.collections.RegularPolyCollection) x, y, c, s = rand(4, 100) @@ -155,7 +160,9 @@ def onpick3(event): #fig.savefig('pscoll.eps') fig.canvas.mpl_connect('pick_event', onpick3) -if 1: # picking images (matplotlib.image.AxesImage) + +def pick_image(): + # picking images (matplotlib.image.AxesImage) fig, ax = plt.subplots() im1 = ax.imshow(rand(10, 5), extent=(1, 2, 1, 2), picker=True) im2 = ax.imshow(rand(5, 10), extent=(3, 4, 1, 2), picker=True) @@ -173,4 +180,9 @@ def onpick4(event): fig.canvas.mpl_connect('pick_event', onpick4) -plt.show() +if __name__ == '__main__': + pick_simple() + pick_custom_hit() + pick_scatter_plot() + pick_image() + plt.show()