From 1219530962654f52d1010e4dc158ecc2ba9187dd Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Sat, 22 Sep 2018 16:15:42 -0700 Subject: [PATCH 01/23] change proposed in issue #12191 removed the confusing if 1: as propsed in #12191 --- examples/axisartist/demo_axisline_style.py | 30 +++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) 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() From 487581ea115918486d2c04109b25d71c01ad40d9 Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Sat, 22 Sep 2018 19:36:26 -0700 Subject: [PATCH 02/23] change requested in #12191 --- examples/event_handling/pick_event_demo.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/event_handling/pick_event_demo.py b/examples/event_handling/pick_event_demo.py index 4f2a924e1d23..54a4ad159eb1 100644 --- a/examples/event_handling/pick_event_demo.py +++ b/examples/event_handling/pick_event_demo.py @@ -74,7 +74,7 @@ def pick_handler(event): import numpy as np from numpy.random import rand -if 1: # simple picking, lines, rectangles and text +def single_pick() # 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 +101,7 @@ 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 +142,7 @@ def onpick2(event): fig.canvas.mpl_connect('pick_event', onpick2) -if 1: # picking on a scatter plot (matplotlib.collections.RegularPolyCollection) +if pick_scatter_plot(): # picking on a scatter plot (matplotlib.collections.RegularPolyCollection) x, y, c, s = rand(4, 100) @@ -155,7 +155,7 @@ 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) From 5df8729da3f8ce811924d49380e9dfa82f52560d Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Mon, 24 Sep 2018 15:09:05 -0700 Subject: [PATCH 03/23] added main() to resolve comments from #12191 --- examples/event_handling/pick_event_demo.py | 154 +-------------------- 1 file changed, 1 insertion(+), 153 deletions(-) diff --git a/examples/event_handling/pick_event_demo.py b/examples/event_handling/pick_event_demo.py index 54a4ad159eb1..63d9ea1e3591 100644 --- a/examples/event_handling/pick_event_demo.py +++ b/examples/event_handling/pick_event_demo.py @@ -21,156 +21,4 @@ off an event if it's data is within epsilon of the mouse event. For some artists like lines and patch collections, the artist may provide additional data to the pick event - that is generated, for example, the indices of the data within - epsilon of the pick event - - function - if picker is callable, it is a user supplied - function which determines whether the artist is hit by the - mouse event. - - hit, props = picker(artist, mouseevent) - - to determine the hit test. If the mouse event is over the - artist, return hit=True and props is a dictionary of properties - you want added to the PickEvent attributes - - -After you have enabled an artist for picking by setting the "picker" -property, you need to connect to the figure canvas pick_event to get -pick callbacks on mouse press events. For example, - - def pick_handler(event): - mouseevent = event.mouseevent - artist = event.artist - # now do something with this... - - -The pick event (matplotlib.backend_bases.PickEvent) which is passed to -your callback is always fired with two attributes: - - mouseevent - the mouse event that generate the pick event. The - mouse event in turn has attributes like x and y (the coordinates in - display space, such as pixels from left, bottom) and xdata, ydata (the - coords in data space). Additionally, you can get information about - which buttons were pressed, which keys were pressed, which Axes - the mouse is over, etc. See matplotlib.backend_bases.MouseEvent - for details. - - artist - the matplotlib.artist that generated the pick event. - -Additionally, certain artists like Line2D and PatchCollection may -attach additional meta data like the indices into the data that meet -the picker criteria (for example, all the points in the line that are within -the specified epsilon tolerance) - -The examples below illustrate each of these methods. -""" - -import matplotlib.pyplot as plt -from matplotlib.lines import Line2D -from matplotlib.patches import Rectangle -from matplotlib.text import Text -from matplotlib.image import AxesImage -import numpy as np -from numpy.random import rand - -def single_pick() # 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')) - line, = ax1.plot(rand(100), 'o', picker=5) # 5 points tolerance - - # pick the rectangle - bars = ax2.bar(range(10), rand(10), picker=True) - for label in ax2.get_xticklabels(): # make the xtick labels pickable - label.set_picker(True) - - def onpick1(event): - if isinstance(event.artist, Line2D): - thisline = event.artist - xdata = thisline.get_xdata() - ydata = thisline.get_ydata() - ind = event.ind - print('onpick1 line:', zip(np.take(xdata, ind), np.take(ydata, ind))) - elif isinstance(event.artist, Rectangle): - patch = event.artist - print('onpick1 patch:', patch.get_path()) - elif isinstance(event.artist, Text): - text = event.artist - print('onpick1 text:', text.get_text()) - - fig.canvas.mpl_connect('pick_event', onpick1) - -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 - # - # hit, props = func(artist, mouseevent) - # - # to determine the hit test. if the mouse event is over the artist, - # return hit=True and props is a dictionary of - # properties you want added to the PickEvent attributes - - def line_picker(line, mouseevent): - """ - find the points within a certain distance from the mouseclick in - data coords and attach some extra attributes, pickx and picky - which are the data points that were picked - """ - if mouseevent.xdata is None: - return False, dict() - xdata = line.get_xdata() - ydata = line.get_ydata() - maxd = 0.05 - d = np.sqrt((xdata - mouseevent.xdata)**2. + (ydata - mouseevent.ydata)**2.) - - ind = np.nonzero(np.less_equal(d, maxd)) - if len(ind): - pickx = np.take(xdata, ind) - picky = np.take(ydata, ind) - props = dict(ind=ind, pickx=pickx, picky=picky) - return True, props - else: - return False, dict() - - def onpick2(event): - print('onpick2 line:', event.pickx, event.picky) - - fig, ax = plt.subplots() - ax.set_title('custom picker for line data') - line, = ax.plot(rand(100), rand(100), 'o', picker=line_picker) - fig.canvas.mpl_connect('pick_event', onpick2) - - -if pick_scatter_plot(): # picking on a scatter plot (matplotlib.collections.RegularPolyCollection) - - x, y, c, s = rand(4, 100) - - def onpick3(event): - ind = event.ind - print('onpick3 scatter:', ind, np.take(x, ind), np.take(y, ind)) - - fig, ax = plt.subplots() - col = ax.scatter(x, y, 100*s, c, picker=True) - #fig.savefig('pscoll.eps') - fig.canvas.mpl_connect('pick_event', onpick3) - -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) - im3 = ax.imshow(rand(20, 25), extent=(1, 2, 3, 4), picker=True) - im4 = ax.imshow(rand(30, 12), extent=(3, 4, 3, 4), picker=True) - ax.axis([0, 5, 0, 5]) - - def onpick4(event): - artist = event.artist - if isinstance(artist, AxesImage): - im = artist - A = im.get_array() - print('onpick4 image', A.shape) - - fig.canvas.mpl_connect('pick_event', onpick4) - - -plt.show() +"test.py" 186L, 6570C 1,1 Top From a6473cde94e8ed59ea96973500791cf305fe0c1a Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Mon, 24 Sep 2018 15:11:19 -0700 Subject: [PATCH 04/23] update #12191 --- examples/event_handling/pick_event_demo.py | 164 ++++++++++++++++++++- 1 file changed, 163 insertions(+), 1 deletion(-) diff --git a/examples/event_handling/pick_event_demo.py b/examples/event_handling/pick_event_demo.py index 63d9ea1e3591..37ec87bec420 100644 --- a/examples/event_handling/pick_event_demo.py +++ b/examples/event_handling/pick_event_demo.py @@ -21,4 +21,166 @@ off an event if it's data is within epsilon of the mouse event. For some artists like lines and patch collections, the artist may provide additional data to the pick event -"test.py" 186L, 6570C 1,1 Top + that is generated, for example, the indices of the data within + epsilon of the pick event + + function - if picker is callable, it is a user supplied + function which determines whether the artist is hit by the + mouse event. + + hit, props = picker(artist, mouseevent) + + to determine the hit test. If the mouse event is over the + artist, return hit=True and props is a dictionary of properties + you want added to the PickEvent attributes + + +After you have enabled an artist for picking by setting the "picker" +property, you need to connect to the figure canvas pick_event to get +pick callbacks on mouse press events. For example, + + def pick_handler(event): + mouseevent = event.mouseevent + artist = event.artist + # now do something with this... + + +The pick event (matplotlib.backend_bases.PickEvent) which is passed to +your callback is always fired with two attributes: + + mouseevent - the mouse event that generate the pick event. The + mouse event in turn has attributes like x and y (the coordinates in + display space, such as pixels from left, bottom) and xdata, ydata (the + coords in data space). Additionally, you can get information about + which buttons were pressed, which keys were pressed, which Axes + the mouse is over, etc. See matplotlib.backend_bases.MouseEvent + for details. + + artist - the matplotlib.artist that generated the pick event. + +Additionally, certain artists like Line2D and PatchCollection may +attach additional meta data like the indices into the data that meet +the picker criteria (for example, all the points in the line that are within +the specified epsilon tolerance) + +The examples below illustrate each of these methods. +""" + +import matplotlib.pyplot as plt +from matplotlib.lines import Line2D +from matplotlib.patches import Rectangle +from matplotlib.text import Text +from matplotlib.image import AxesImage +import numpy as np +from numpy.random import rand + +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')) + line, = ax1.plot(rand(100), 'o', picker=5) # 5 points tolerance + + # pick the rectangle + bars = ax2.bar(range(10), rand(10), picker=True) + for label in ax2.get_xticklabels(): # make the xtick labels pickable + label.set_picker(True) + + def onpick1(event): + if isinstance(event.artist, Line2D): + thisline = event.artist + xdata = thisline.get_xdata() + ydata = thisline.get_ydata() + ind = event.ind + print('onpick1 line:', zip(np.take(xdata, ind), np.take(ydata, ind))) + elif isinstance(event.artist, Rectangle): + patch = event.artist + print('onpick1 patch:', patch.get_path()) + elif isinstance(event.artist, Text): + text = event.artist + print('onpick1 text:', text.get_text()) + + fig.canvas.mpl_connect('pick_event', onpick1) + plt.show() + +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 + # + # hit, props = func(artist, mouseevent) + # + # to determine the hit test. if the mouse event is over the artist, + # return hit=True and props is a dictionary of + # properties you want added to the PickEvent attributes + + def line_picker(line, mouseevent): + """ + find the points within a certain distance from the mouseclick in + data coords and attach some extra attributes, pickx and picky + which are the data points that were picked + """ + if mouseevent.xdata is None: + return False, dict() + xdata = line.get_xdata() + ydata = line.get_ydata() + maxd = 0.05 + d = np.sqrt((xdata - mouseevent.xdata)**2. + (ydata - mouseevent.ydata)**2.) + + ind = np.nonzero(np.less_equal(d, maxd)) + if len(ind): + pickx = np.take(xdata, ind) + picky = np.take(ydata, ind) + props = dict(ind=ind, pickx=pickx, picky=picky) + return True, props + else: + return False, dict() + + def onpick2(event): + print('onpick2 line:', event.pickx, event.picky) + + fig, ax = plt.subplots() + ax.set_title('custom picker for line data') + line, = ax.plot(rand(100), rand(100), 'o', picker=line_picker) + fig.canvas.mpl_connect('pick_event', onpick2) + plt.show() + +def pick_scatter_plot(): + # picking on a scatter plot (matplotlib.collections.RegularPolyCollection) + + x, y, c, s = rand(4, 100) + + def onpick3(event): + ind = event.ind + print('onpick3 scatter:', ind, np.take(x, ind), np.take(y, ind)) + + fig, ax = plt.subplots() + col = ax.scatter(x, y, 100*s, c, picker=True) + #fig.savefig('pscoll.eps') + fig.canvas.mpl_connect('pick_event', onpick3) + plt.show() + +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) + im3 = ax.imshow(rand(20, 25), extent=(1, 2, 3, 4), picker=True) + im4 = ax.imshow(rand(30, 12), extent=(3, 4, 3, 4), picker=True) + ax.axis([0, 5, 0, 5]) + + def onpick4(event): + artist = event.artist + if isinstance(artist, AxesImage): + im = artist + A = im.get_array() + print('onpick4 image', A.shape) + + fig.canvas.mpl_connect('pick_event', onpick4) + plt.show() + +if __name__ == '__main__': + pick_simple() + pick_custom_hit() + pick_scatter_plot() + pick_image() From a9fee9c248a642ac8b380f3c8ccc99ce3a5dc2c5 Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Mon, 24 Sep 2018 15:41:35 -0700 Subject: [PATCH 05/23] flake-8 corrections #12191 --- examples/event_handling/pick_event_demo.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/event_handling/pick_event_demo.py b/examples/event_handling/pick_event_demo.py index 37ec87bec420..48e8c733cf48 100644 --- a/examples/event_handling/pick_event_demo.py +++ b/examples/event_handling/pick_event_demo.py @@ -74,6 +74,7 @@ def pick_handler(event): import numpy as np from numpy.random import rand + def pick_simple(): # simple picking, lines, rectangles and text fig, (ax1, ax2) = plt.subplots(2, 1) @@ -103,6 +104,7 @@ def onpick1(event): fig.canvas.mpl_connect('pick_event', onpick1) plt.show() + def pick_custom_hit(): # picking with a custom hit test function # you can define custom pickers by setting picker to a callable @@ -145,6 +147,7 @@ def onpick2(event): fig.canvas.mpl_connect('pick_event', onpick2) plt.show() + def pick_scatter_plot(): # picking on a scatter plot (matplotlib.collections.RegularPolyCollection) @@ -160,6 +163,7 @@ def onpick3(event): fig.canvas.mpl_connect('pick_event', onpick3) plt.show() + def pick_image(): # picking images (matplotlib.image.AxesImage) fig, ax = plt.subplots() @@ -179,6 +183,7 @@ def onpick4(event): fig.canvas.mpl_connect('pick_event', onpick4) plt.show() + if __name__ == '__main__': pick_simple() pick_custom_hit() From 0c98309ffeca2c7fd244e94c80ff93ad20328b4c Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Mon, 24 Sep 2018 15:59:35 -0700 Subject: [PATCH 06/23] update ```plt.show``` for #12191 --- examples/event_handling/pick_event_demo.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/examples/event_handling/pick_event_demo.py b/examples/event_handling/pick_event_demo.py index 48e8c733cf48..9bc7e1198c05 100644 --- a/examples/event_handling/pick_event_demo.py +++ b/examples/event_handling/pick_event_demo.py @@ -102,7 +102,6 @@ def onpick1(event): print('onpick1 text:', text.get_text()) fig.canvas.mpl_connect('pick_event', onpick1) - plt.show() def pick_custom_hit(): @@ -145,7 +144,6 @@ def onpick2(event): ax.set_title('custom picker for line data') line, = ax.plot(rand(100), rand(100), 'o', picker=line_picker) fig.canvas.mpl_connect('pick_event', onpick2) - plt.show() def pick_scatter_plot(): @@ -161,7 +159,6 @@ def onpick3(event): col = ax.scatter(x, y, 100*s, c, picker=True) #fig.savefig('pscoll.eps') fig.canvas.mpl_connect('pick_event', onpick3) - plt.show() def pick_image(): @@ -181,7 +178,6 @@ def onpick4(event): print('onpick4 image', A.shape) fig.canvas.mpl_connect('pick_event', onpick4) - plt.show() if __name__ == '__main__': @@ -189,3 +185,4 @@ def onpick4(event): pick_custom_hit() pick_scatter_plot() pick_image() + plt.show() From e64129f86bce2c274a18ff16ce2f46180051912a Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Mon, 24 Sep 2018 16:46:59 -0700 Subject: [PATCH 07/23] flake8 update #12191 --- examples/event_handling/pick_event_demo.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/event_handling/pick_event_demo.py b/examples/event_handling/pick_event_demo.py index 9bc7e1198c05..7198bff484a5 100644 --- a/examples/event_handling/pick_event_demo.py +++ b/examples/event_handling/pick_event_demo.py @@ -103,7 +103,7 @@ def onpick1(event): fig.canvas.mpl_connect('pick_event', onpick1) - + def pick_custom_hit(): # picking with a custom hit test function # you can define custom pickers by setting picker to a callable @@ -145,7 +145,7 @@ def onpick2(event): line, = ax.plot(rand(100), rand(100), 'o', picker=line_picker) fig.canvas.mpl_connect('pick_event', onpick2) - + def pick_scatter_plot(): # picking on a scatter plot (matplotlib.collections.RegularPolyCollection) @@ -160,8 +160,8 @@ def onpick3(event): #fig.savefig('pscoll.eps') fig.canvas.mpl_connect('pick_event', onpick3) - -def pick_image(): + +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) @@ -179,7 +179,7 @@ def onpick4(event): fig.canvas.mpl_connect('pick_event', onpick4) - + if __name__ == '__main__': pick_simple() pick_custom_hit() From 0c19bf798332e7ae504586eb43e57a298687ba9d Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Mon, 24 Sep 2018 21:40:04 -0700 Subject: [PATCH 08/23] Update demo_annotation_box.py --- examples/text_labels_and_annotations/demo_annotation_box.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/text_labels_and_annotations/demo_annotation_box.py b/examples/text_labels_and_annotations/demo_annotation_box.py index 0518d7d68b64..7a1ff113cec2 100644 --- a/examples/text_labels_and_annotations/demo_annotation_box.py +++ b/examples/text_labels_and_annotations/demo_annotation_box.py @@ -13,7 +13,7 @@ from matplotlib.cbook import get_sample_data -if 1: +if __name__=="__main__": fig, ax = plt.subplots() # Define a 1st position to annotate (display it with a marker) From f1e3ccd1f1552017cf480c199f41790e6cc66c90 Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Mon, 24 Sep 2018 21:41:14 -0700 Subject: [PATCH 09/23] Update demo_agg_filter.py --- examples/misc/demo_agg_filter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/misc/demo_agg_filter.py b/examples/misc/demo_agg_filter.py index 6a1d2c4e6588..9dd788569382 100644 --- a/examples/misc/demo_agg_filter.py +++ b/examples/misc/demo_agg_filter.py @@ -307,7 +307,7 @@ def light_filter_pie(ax): shadow.set_zorder(pies[0][0].get_zorder() - 0.1) -if 1: +if __name__=="__main__": plt.figure(figsize=(6, 6)) plt.subplots_adjust(left=0.05, right=0.95) From 2c58938b461bb391903ffc49d219ae3e62c29481 Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Mon, 24 Sep 2018 21:41:51 -0700 Subject: [PATCH 10/23] Update patheffect_demo.py --- examples/misc/patheffect_demo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/misc/patheffect_demo.py b/examples/misc/patheffect_demo.py index 60c24b7ea6b5..ccd1178bd6e7 100644 --- a/examples/misc/patheffect_demo.py +++ b/examples/misc/patheffect_demo.py @@ -8,7 +8,7 @@ import matplotlib.patheffects as PathEffects import numpy as np -if 1: +if __name__=="__main__": plt.figure(figsize=(8, 3)) ax1 = plt.subplot(131) ax1.imshow([[1, 2], [2, 3]]) From 19cdb6dfc8c07101c446600a7116d8f85fddbed4 Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Mon, 24 Sep 2018 21:42:47 -0700 Subject: [PATCH 11/23] Update demo_text_rotation_mode.py --- examples/text_labels_and_annotations/demo_text_rotation_mode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/text_labels_and_annotations/demo_text_rotation_mode.py b/examples/text_labels_and_annotations/demo_text_rotation_mode.py index 4eb8ae528b43..29c8cac96f7d 100644 --- a/examples/text_labels_and_annotations/demo_text_rotation_mode.py +++ b/examples/text_labels_and_annotations/demo_text_rotation_mode.py @@ -42,7 +42,7 @@ def test_rotation_mode(fig, mode, subplot_location): i += 1 -if 1: +if __name__=="__main__": import matplotlib.pyplot as plt fig = plt.figure(figsize=(5.5, 4)) test_rotation_mode(fig, "default", 121) From 24d6d3866de950129e01c21ed8851641be779a08 Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Mon, 24 Sep 2018 21:43:24 -0700 Subject: [PATCH 12/23] Update demo_text_path.py --- examples/text_labels_and_annotations/demo_text_path.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/text_labels_and_annotations/demo_text_path.py b/examples/text_labels_and_annotations/demo_text_path.py index 69dc32386c9b..f5bf386e97fe 100644 --- a/examples/text_labels_and_annotations/demo_text_path.py +++ b/examples/text_labels_and_annotations/demo_text_path.py @@ -56,7 +56,7 @@ def draw(self, renderer=None): mpatches.PathPatch.draw(self, renderer) -if 1: +if __name__=="__main__": usetex = plt.rcParams["text.usetex"] From ddb647da12eeea99e6d7660a8a8171075ee7ac91 Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Mon, 24 Sep 2018 21:44:42 -0700 Subject: [PATCH 13/23] Update demo_curvelinear_grid.py --- examples/axisartist/demo_curvelinear_grid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/axisartist/demo_curvelinear_grid.py b/examples/axisartist/demo_curvelinear_grid.py index 8fb4ef6b9d95..6f25ed31fe07 100644 --- a/examples/axisartist/demo_curvelinear_grid.py +++ b/examples/axisartist/demo_curvelinear_grid.py @@ -131,7 +131,7 @@ def curvelinear_test2(fig): ax1.grid(True, zorder=0) -if 1: +if __name__=="__main__": fig = plt.figure(figsize=(7, 4)) curvelinear_test1(fig) From a5e8f082f810b56955532ca51e04470d343f4c09 Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Mon, 24 Sep 2018 21:45:26 -0700 Subject: [PATCH 14/23] Update demo_curvelinear_grid2.py --- examples/axisartist/demo_curvelinear_grid2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/axisartist/demo_curvelinear_grid2.py b/examples/axisartist/demo_curvelinear_grid2.py index ca9fdbdc784f..8e40edcd1062 100644 --- a/examples/axisartist/demo_curvelinear_grid2.py +++ b/examples/axisartist/demo_curvelinear_grid2.py @@ -64,7 +64,7 @@ def inv_tr(x, y): grid_helper.grid_finder.grid_locator2._nbins = 6 -if 1: +if __name__=="__main__": fig = plt.figure(figsize=(7, 4)) curvelinear_test1(fig) plt.show() From 67e3738da9817fef8be21a7844180e625d439abb Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Tue, 25 Sep 2018 10:25:08 -0700 Subject: [PATCH 15/23] flake8 compliant --- examples/axisartist/demo_curvelinear_grid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/axisartist/demo_curvelinear_grid.py b/examples/axisartist/demo_curvelinear_grid.py index 6f25ed31fe07..512ca31bb99c 100644 --- a/examples/axisartist/demo_curvelinear_grid.py +++ b/examples/axisartist/demo_curvelinear_grid.py @@ -131,7 +131,7 @@ def curvelinear_test2(fig): ax1.grid(True, zorder=0) -if __name__=="__main__": +if __name__ == "__main__": fig = plt.figure(figsize=(7, 4)) curvelinear_test1(fig) From 8867b198f5186e56c5bca6516115c254b9d2a386 Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Tue, 25 Sep 2018 10:25:30 -0700 Subject: [PATCH 16/23] flake8 compliant --- examples/axisartist/demo_curvelinear_grid2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/axisartist/demo_curvelinear_grid2.py b/examples/axisartist/demo_curvelinear_grid2.py index 8e40edcd1062..4fb2872bd0f5 100644 --- a/examples/axisartist/demo_curvelinear_grid2.py +++ b/examples/axisartist/demo_curvelinear_grid2.py @@ -64,7 +64,7 @@ def inv_tr(x, y): grid_helper.grid_finder.grid_locator2._nbins = 6 -if __name__=="__main__": +if __name__ == "__main__": fig = plt.figure(figsize=(7, 4)) curvelinear_test1(fig) plt.show() From afc4923945f5693fe3a5ea895ffdf85308b0ed1e Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Tue, 25 Sep 2018 10:26:01 -0700 Subject: [PATCH 17/23] flake8 compliant --- examples/misc/demo_agg_filter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/misc/demo_agg_filter.py b/examples/misc/demo_agg_filter.py index 9dd788569382..7635566cc028 100644 --- a/examples/misc/demo_agg_filter.py +++ b/examples/misc/demo_agg_filter.py @@ -307,7 +307,7 @@ def light_filter_pie(ax): shadow.set_zorder(pies[0][0].get_zorder() - 0.1) -if __name__=="__main__": +if __name__ == "__main__": plt.figure(figsize=(6, 6)) plt.subplots_adjust(left=0.05, right=0.95) From 1d9161a8cd0539a65b00034d1940056d7c9d8e91 Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Tue, 25 Sep 2018 10:30:21 -0700 Subject: [PATCH 18/23] Update patheffect_demo.py --- examples/misc/patheffect_demo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/misc/patheffect_demo.py b/examples/misc/patheffect_demo.py index ccd1178bd6e7..b3b29922a173 100644 --- a/examples/misc/patheffect_demo.py +++ b/examples/misc/patheffect_demo.py @@ -8,7 +8,7 @@ import matplotlib.patheffects as PathEffects import numpy as np -if __name__=="__main__": +if __name__ == "__main__": plt.figure(figsize=(8, 3)) ax1 = plt.subplot(131) ax1.imshow([[1, 2], [2, 3]]) From 13680b5016b1efcb8bdf954f8c85685014a07913 Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Tue, 25 Sep 2018 10:30:50 -0700 Subject: [PATCH 19/23] Update demo_annotation_box.py --- examples/text_labels_and_annotations/demo_annotation_box.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/text_labels_and_annotations/demo_annotation_box.py b/examples/text_labels_and_annotations/demo_annotation_box.py index 7a1ff113cec2..4acf4d8b0d78 100644 --- a/examples/text_labels_and_annotations/demo_annotation_box.py +++ b/examples/text_labels_and_annotations/demo_annotation_box.py @@ -13,7 +13,7 @@ from matplotlib.cbook import get_sample_data -if __name__=="__main__": +if __name__ == "__main__": fig, ax = plt.subplots() # Define a 1st position to annotate (display it with a marker) From 83550672451b128d869ed28c8615c75eec986961 Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Tue, 25 Sep 2018 10:32:12 -0700 Subject: [PATCH 20/23] flake8 compliant --- examples/text_labels_and_annotations/demo_text_path.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/text_labels_and_annotations/demo_text_path.py b/examples/text_labels_and_annotations/demo_text_path.py index f5bf386e97fe..f3df20ca57a5 100644 --- a/examples/text_labels_and_annotations/demo_text_path.py +++ b/examples/text_labels_and_annotations/demo_text_path.py @@ -56,7 +56,7 @@ def draw(self, renderer=None): mpatches.PathPatch.draw(self, renderer) -if __name__=="__main__": +if __name__ == "__main__": usetex = plt.rcParams["text.usetex"] From 272b166b6e02f61b8bc5848b93442d639a85bc36 Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Tue, 25 Sep 2018 10:32:25 -0700 Subject: [PATCH 21/23] Update demo_text_rotation_mode.py --- examples/text_labels_and_annotations/demo_text_rotation_mode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/text_labels_and_annotations/demo_text_rotation_mode.py b/examples/text_labels_and_annotations/demo_text_rotation_mode.py index 29c8cac96f7d..0d161aada8c5 100644 --- a/examples/text_labels_and_annotations/demo_text_rotation_mode.py +++ b/examples/text_labels_and_annotations/demo_text_rotation_mode.py @@ -42,7 +42,7 @@ def test_rotation_mode(fig, mode, subplot_location): i += 1 -if __name__=="__main__": +if __name__ == "__main__": import matplotlib.pyplot as plt fig = plt.figure(figsize=(5.5, 4)) test_rotation_mode(fig, "default", 121) From 54f4ac74cc49678e10eafc39752327ecc91d17dc Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Wed, 26 Sep 2018 17:37:09 -0700 Subject: [PATCH 22/23] Update patheffect_demo.py --- examples/misc/patheffect_demo.py | 73 ++++++++++++++++---------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/examples/misc/patheffect_demo.py b/examples/misc/patheffect_demo.py index b3b29922a173..4455d63cecf6 100644 --- a/examples/misc/patheffect_demo.py +++ b/examples/misc/patheffect_demo.py @@ -8,40 +8,39 @@ import matplotlib.patheffects as PathEffects import numpy as np -if __name__ == "__main__": - plt.figure(figsize=(8, 3)) - ax1 = plt.subplot(131) - ax1.imshow([[1, 2], [2, 3]]) - txt = ax1.annotate("test", (1., 1.), (0., 0), - arrowprops=dict(arrowstyle="->", - connectionstyle="angle3", lw=2), - size=20, ha="center", - path_effects=[PathEffects.withStroke(linewidth=3, - foreground="w")]) - txt.arrow_patch.set_path_effects([ - PathEffects.Stroke(linewidth=5, foreground="w"), - PathEffects.Normal()]) - - pe = [PathEffects.withStroke(linewidth=3, - foreground="w")] - ax1.grid(True, linestyle="-", path_effects=pe) - - ax2 = plt.subplot(132) - arr = np.arange(25).reshape((5, 5)) - ax2.imshow(arr) - cntr = ax2.contour(arr, colors="k") - - plt.setp(cntr.collections, path_effects=[ - PathEffects.withStroke(linewidth=3, foreground="w")]) - - clbls = ax2.clabel(cntr, fmt="%2.0f", use_clabeltext=True) - plt.setp(clbls, path_effects=[ - PathEffects.withStroke(linewidth=3, foreground="w")]) - - # shadow as a path effect - ax3 = plt.subplot(133) - p1, = ax3.plot([0, 1], [0, 1]) - leg = ax3.legend([p1], ["Line 1"], fancybox=True, loc='upper left') - leg.legendPatch.set_path_effects([PathEffects.withSimplePatchShadow()]) - - plt.show() +plt.figure(figsize=(8, 3)) +ax1 = plt.subplot(131) +ax1.imshow([[1, 2], [2, 3]]) +txt = ax1.annotate("test", (1., 1.), (0., 0), + arrowprops=dict(arrowstyle="->", + connectionstyle="angle3", lw=2), + size=20, ha="center", + path_effects=[PathEffects.withStroke(linewidth=3, + foreground="w")]) +txt.arrow_patch.set_path_effects([ + PathEffects.Stroke(linewidth=5, foreground="w"), + PathEffects.Normal()]) + +pe = [PathEffects.withStroke(linewidth=3, + foreground="w")] +ax1.grid(True, linestyle="-", path_effects=pe) + +ax2 = plt.subplot(132) +arr = np.arange(25).reshape((5, 5)) +ax2.imshow(arr) +cntr = ax2.contour(arr, colors="k") + +plt.setp(cntr.collections, path_effects=[ + PathEffects.withStroke(linewidth=3, foreground="w")]) + +clbls = ax2.clabel(cntr, fmt="%2.0f", use_clabeltext=True) +plt.setp(clbls, path_effects=[ + PathEffects.withStroke(linewidth=3, foreground="w")]) + +# shadow as a path effect +ax3 = plt.subplot(133) +p1, = ax3.plot([0, 1], [0, 1]) +leg = ax3.legend([p1], ["Line 1"], fancybox=True, loc='upper left') +leg.legendPatch.set_path_effects([PathEffects.withSimplePatchShadow()]) + +plt.show() From 222ac6402a8b2ba189c44eaf3c100af63c705f71 Mon Sep 17 00:00:00 2001 From: Abhinuv Nitin Pitale Date: Wed, 26 Sep 2018 17:37:51 -0700 Subject: [PATCH 23/23] Update demo_annotation_box.py --- .../demo_annotation_box.py | 165 +++++++++--------- 1 file changed, 82 insertions(+), 83 deletions(-) diff --git a/examples/text_labels_and_annotations/demo_annotation_box.py b/examples/text_labels_and_annotations/demo_annotation_box.py index 4acf4d8b0d78..9ffbc65b021a 100644 --- a/examples/text_labels_and_annotations/demo_annotation_box.py +++ b/examples/text_labels_and_annotations/demo_annotation_box.py @@ -13,86 +13,85 @@ from matplotlib.cbook import get_sample_data -if __name__ == "__main__": - fig, ax = plt.subplots() - - # Define a 1st position to annotate (display it with a marker) - xy = (0.5, 0.7) - ax.plot(xy[0], xy[1], ".r") - - # Annotate the 1st position with a text box ('Test 1') - offsetbox = TextArea("Test 1", minimumdescent=False) - - ab = AnnotationBbox(offsetbox, xy, - xybox=(-20, 40), - xycoords='data', - boxcoords="offset points", - arrowprops=dict(arrowstyle="->")) - ax.add_artist(ab) - - # Annotate the 1st position with another text box ('Test') - offsetbox = TextArea("Test", minimumdescent=False) - - ab = AnnotationBbox(offsetbox, xy, - xybox=(1.02, xy[1]), - xycoords='data', - boxcoords=("axes fraction", "data"), - box_alignment=(0., 0.5), - arrowprops=dict(arrowstyle="->")) - ax.add_artist(ab) - - # Define a 2nd position to annotate (don't display with a marker this time) - xy = [0.3, 0.55] - - # Annotate the 2nd position with a circle patch - da = DrawingArea(20, 20, 0, 0) - p = Circle((10, 10), 10) - da.add_artist(p) - - ab = AnnotationBbox(da, xy, - xybox=(1.02, xy[1]), - xycoords='data', - boxcoords=("axes fraction", "data"), - box_alignment=(0., 0.5), - arrowprops=dict(arrowstyle="->")) - - ax.add_artist(ab) - - # Annotate the 2nd position with an image (a generated array of pixels) - arr = np.arange(100).reshape((10, 10)) - im = OffsetImage(arr, zoom=2) - im.image.axes = ax - - ab = AnnotationBbox(im, xy, - xybox=(-50., 50.), - xycoords='data', - boxcoords="offset points", - pad=0.3, - arrowprops=dict(arrowstyle="->")) - - ax.add_artist(ab) - - # Annotate the 2nd position with another image (a Grace Hopper portrait) - fn = get_sample_data("grace_hopper.png", asfileobj=False) - arr_img = plt.imread(fn, format='png') - - imagebox = OffsetImage(arr_img, zoom=0.2) - imagebox.image.axes = ax - - ab = AnnotationBbox(imagebox, xy, - xybox=(120., -80.), - xycoords='data', - boxcoords="offset points", - pad=0.5, - arrowprops=dict( - arrowstyle="->", - connectionstyle="angle,angleA=0,angleB=90,rad=3") - ) - - ax.add_artist(ab) - - # Fix the display limits to see everything - ax.set_xlim(0, 1) - ax.set_ylim(0, 1) - - plt.show() +fig, ax = plt.subplots() + +# Define a 1st position to annotate (display it with a marker) +xy = (0.5, 0.7) +ax.plot(xy[0], xy[1], ".r") + +# Annotate the 1st position with a text box ('Test 1') +offsetbox = TextArea("Test 1", minimumdescent=False) + +ab = AnnotationBbox(offsetbox, xy, + xybox=(-20, 40), + xycoords='data', + boxcoords="offset points", + arrowprops=dict(arrowstyle="->")) +ax.add_artist(ab) + +# Annotate the 1st position with another text box ('Test') +offsetbox = TextArea("Test", minimumdescent=False) + +ab = AnnotationBbox(offsetbox, xy, + xybox=(1.02, xy[1]), + xycoords='data', + boxcoords=("axes fraction", "data"), + box_alignment=(0., 0.5), + arrowprops=dict(arrowstyle="->")) +ax.add_artist(ab) + +# Define a 2nd position to annotate (don't display with a marker this time) +xy = [0.3, 0.55] + +# Annotate the 2nd position with a circle patch +da = DrawingArea(20, 20, 0, 0) +p = Circle((10, 10), 10) +da.add_artist(p) + +ab = AnnotationBbox(da, xy, + xybox=(1.02, xy[1]), + xycoords='data', + boxcoords=("axes fraction", "data"), + box_alignment=(0., 0.5), + arrowprops=dict(arrowstyle="->")) + +ax.add_artist(ab) + +# Annotate the 2nd position with an image (a generated array of pixels) +arr = np.arange(100).reshape((10, 10)) +im = OffsetImage(arr, zoom=2) +im.image.axes = ax + +ab = AnnotationBbox(im, xy, + xybox=(-50., 50.), + xycoords='data', + boxcoords="offset points", + pad=0.3, + arrowprops=dict(arrowstyle="->")) + +ax.add_artist(ab) + +# Annotate the 2nd position with another image (a Grace Hopper portrait) +fn = get_sample_data("grace_hopper.png", asfileobj=False) +arr_img = plt.imread(fn, format='png') + +imagebox = OffsetImage(arr_img, zoom=0.2) +imagebox.image.axes = ax + +ab = AnnotationBbox(imagebox, xy, + xybox=(120., -80.), + xycoords='data', + boxcoords="offset points", + pad=0.5, + arrowprops=dict( + arrowstyle="->", + connectionstyle="angle,angleA=0,angleB=90,rad=3") + ) + +ax.add_artist(ab) + +# Fix the display limits to see everything +ax.set_xlim(0, 1) +ax.set_ylim(0, 1) + +plt.show()