From 0e07fd2ba8605de1961123dd16e1831a2b21177e Mon Sep 17 00:00:00 2001 From: mlub Date: Sun, 17 Jul 2016 18:50:55 -0500 Subject: [PATCH 1/2] 2.0 Examples fixes. See #6762 These are fixes for all issues found in axes_grid, color, and event_handling sections on the examples page. axis_grid/demo_colorbar_with_inset_locator.py - changed interpolation from the default(previously bilinear now none) to 'bilinear' to match 1.5.1 example axes_grid1/simple_axesgrid.py - set interpolation to bilinear axisartist/demo_curvelinear_grid.py - Set linewidth=2.0 and grid zorder=0 so the plotted lines actually visible event_handling/keypress_demo.py - added usage instruction as axes title event_handling/lasso_demo.py - added usage instruction as axes title event_handling/looking_glass.py - added usage instruction as axes title event_handling/resample.py - removed gtk and hardcoded wave file dependencies and just created a sample signal within the script event_handling/trifinder_event_demo.py - zip(l1,l2) call changed to list(zip(l1,l2)) to be python3 compatible event_handling/viewlims.py - The focus box that is supposed to appear in the left axes when user zooms in the right axes wasn't visible. Set linewidth=1.0 --- .../demo_colorbar_with_inset_locator.py | 4 ++-- examples/axes_grid1/simple_axesgrid.py | 2 +- examples/axisartist/demo_curvelinear_grid.py | 9 ++++---- examples/event_handling/keypress_demo.py | 2 +- examples/event_handling/lasso_demo.py | 3 ++- examples/event_handling/looking_glass.py | 2 +- examples/event_handling/resample.py | 22 +++++++++---------- .../event_handling/trifinder_event_demo.py | 2 +- examples/event_handling/viewlims.py | 3 ++- 9 files changed, 25 insertions(+), 24 deletions(-) diff --git a/examples/axes_grid1/demo_colorbar_with_inset_locator.py b/examples/axes_grid1/demo_colorbar_with_inset_locator.py index 72a920b402c5..157ab07fb4fd 100644 --- a/examples/axes_grid1/demo_colorbar_with_inset_locator.py +++ b/examples/axes_grid1/demo_colorbar_with_inset_locator.py @@ -9,7 +9,7 @@ height="5%", # height : 50% loc=1) -im1 = ax1.imshow([[1, 2], [2, 3]]) +im1 = ax1.imshow([[1, 2], [2, 3]], interpolation='bilinear') plt.colorbar(im1, cax=axins1, orientation="horizontal", ticks=[1, 2, 3]) axins1.xaxis.set_ticks_position("bottom") @@ -26,7 +26,7 @@ # of the legend. you may want to play with the borderpad value and # the bbox_to_anchor coordinate. -im = ax2.imshow([[1, 2], [2, 3]]) +im = ax2.imshow([[1, 2], [2, 3]], interpolation='bilinear') plt.colorbar(im, cax=axins, ticks=[1, 2, 3]) plt.draw() diff --git a/examples/axes_grid1/simple_axesgrid.py b/examples/axes_grid1/simple_axesgrid.py index b8c45f2aae6d..c96a9f2801f8 100644 --- a/examples/axes_grid1/simple_axesgrid.py +++ b/examples/axes_grid1/simple_axesgrid.py @@ -12,6 +12,6 @@ ) for i in range(4): - grid[i].imshow(im) # The AxesGrid object work as a list of axes. + grid[i].imshow(im, interpolation='bilinear') # The AxesGrid object work as a list of axes. plt.show() diff --git a/examples/axisartist/demo_curvelinear_grid.py b/examples/axisartist/demo_curvelinear_grid.py index 4080aaadc974..bae8ab9ae916 100644 --- a/examples/axisartist/demo_curvelinear_grid.py +++ b/examples/axisartist/demo_curvelinear_grid.py @@ -34,7 +34,7 @@ def inv_tr(x, y): fig.add_subplot(ax1) xx, yy = tr([3, 6], [5.0, 10.]) - ax1.plot(xx, yy) + ax1.plot(xx, yy, linewidth=2.0) ax1.set_aspect(1.) ax1.set_xlim(0, 10.) @@ -42,7 +42,7 @@ def inv_tr(x, y): ax1.axis["t"] = ax1.new_floating_axis(0, 3.) ax1.axis["t2"] = ax1.new_floating_axis(1, 7.) - ax1.grid(True) + ax1.grid(True, zorder=0) import mpl_toolkits.axisartist.angle_helper as angle_helper @@ -107,13 +107,14 @@ def curvelinear_test2(fig): ax1.parasites.append(ax2) intp = cbook.simple_linear_interpolation ax2.plot(intp(np.array([0, 30]), 50), - intp(np.array([10., 10.]), 50)) + intp(np.array([10., 10.]), 50), + linewidth=2.0) ax1.set_aspect(1.) ax1.set_xlim(-5, 12) ax1.set_ylim(-5, 10) - ax1.grid(True) + ax1.grid(True, zorder=0) if 1: fig = plt.figure(1, figsize=(7, 4)) diff --git a/examples/event_handling/keypress_demo.py b/examples/event_handling/keypress_demo.py index 30ac00e4efbe..db8c71c96918 100755 --- a/examples/event_handling/keypress_demo.py +++ b/examples/event_handling/keypress_demo.py @@ -21,5 +21,5 @@ def press(event): ax.plot(np.random.rand(12), np.random.rand(12), 'go') xl = ax.set_xlabel('easy come, easy go') - +ax.set_title('Press a key') plt.show() diff --git a/examples/event_handling/lasso_demo.py b/examples/event_handling/lasso_demo.py index c704692e1277..8cc8d662043d 100644 --- a/examples/event_handling/lasso_demo.py +++ b/examples/event_handling/lasso_demo.py @@ -77,8 +77,9 @@ def onpress(self, event): if __name__ == '__main__': data = [Datum(*xy) for xy in rand(100, 2)] - ax = plt.axes(xlim=(0, 1), ylim=(0, 1), autoscale_on=False) + ax.set_title('Lasso points using left mouse button') + lman = LassoManager(ax, data) plt.show() diff --git a/examples/event_handling/looking_glass.py b/examples/event_handling/looking_glass.py index b981a4ec7ff1..8d481fe31a73 100644 --- a/examples/event_handling/looking_glass.py +++ b/examples/event_handling/looking_glass.py @@ -10,7 +10,7 @@ ax.plot(x, y, alpha=0.2) line, = ax.plot(x, y, alpha=1.0, clip_path=circ) - +ax.set_title("Left click and drag to move looking glass") class EventHandler(object): def __init__(self): diff --git a/examples/event_handling/resample.py b/examples/event_handling/resample.py index f8f398bb118a..0ca5bc88edcd 100644 --- a/examples/event_handling/resample.py +++ b/examples/event_handling/resample.py @@ -1,6 +1,5 @@ import numpy as np import matplotlib.pyplot as plt -from scikits.audiolab import wavread # A class that will downsample the data and recompute when zoomed. @@ -8,19 +7,18 @@ class DataDisplayDownsampler(object): def __init__(self, xdata, ydata): self.origYData = ydata self.origXData = xdata - self.numpts = 3000 + self.ratio = 5 self.delta = xdata[-1] - xdata[0] - def resample(self, xstart, xend): + def downsample(self, xstart, xend): # Very simple downsampling that takes the points within the range # and picks every Nth point mask = (self.origXData > xstart) & (self.origXData < xend) xdata = self.origXData[mask] - ratio = int(xdata.size / self.numpts) + 1 - xdata = xdata[::ratio] + xdata = xdata[::self.ratio] ydata = self.origYData[mask] - ydata = ydata[::ratio] + ydata = ydata[::self.ratio] return xdata, ydata @@ -33,21 +31,21 @@ def update(self, ax): self.line.set_data(*self.downsample(xstart, xend)) ax.figure.canvas.draw_idle() -# Read data -data = wavread('/usr/share/sounds/purple/receive.wav')[0] -ydata = np.tile(data[:, 0], 100) -xdata = np.arange(ydata.size) +# Create a signal +xdata = np.linspace(16,365,365-16) +ydata = np.sin(2*np.pi*xdata/153) + np.cos(2*np.pi*xdata/127); d = DataDisplayDownsampler(xdata, ydata) fig, ax = plt.subplots() # Hook up the line -xdata, ydata = d.downsample(xdata[0], xdata[-1]) -d.line, = ax.plot(xdata, ydata) +d.line, = ax.plot(xdata, ydata,'o-') ax.set_autoscale_on(False) # Otherwise, infinite loop # Connect for changing the view limits ax.callbacks.connect('xlim_changed', d.update) plt.show() + + diff --git a/examples/event_handling/trifinder_event_demo.py b/examples/event_handling/trifinder_event_demo.py index fd7ccc77d400..0c45c78c4df5 100644 --- a/examples/event_handling/trifinder_event_demo.py +++ b/examples/event_handling/trifinder_event_demo.py @@ -17,7 +17,7 @@ def update_polygon(tri): points = triangulation.triangles[tri] xs = triangulation.x[points] ys = triangulation.y[points] - polygon.set_xy(zip(xs, ys)) + polygon.set_xy(list(zip(xs, ys))) def motion_notify(event): diff --git a/examples/event_handling/viewlims.py b/examples/event_handling/viewlims.py index 7f0a628d1238..18dba5e21b08 100644 --- a/examples/event_handling/viewlims.py +++ b/examples/event_handling/viewlims.py @@ -64,7 +64,7 @@ def ax_update(self, ax): ax1.imshow(Z, origin='lower', extent=(md.x.min(), md.x.max(), md.y.min(), md.y.max())) ax2.imshow(Z, origin='lower', extent=(md.x.min(), md.x.max(), md.y.min(), md.y.max())) -rect = UpdatingRect([0, 0], 0, 0, facecolor='None', edgecolor='black') +rect = UpdatingRect([0, 0], 0, 0, facecolor='None', edgecolor='black', linewidth=1.0) rect.set_bounds(*ax2.viewLim.bounds) ax1.add_patch(rect) @@ -74,5 +74,6 @@ def ax_update(self, ax): ax2.callbacks.connect('xlim_changed', md.ax_update) ax2.callbacks.connect('ylim_changed', md.ax_update) +ax2.set_title("Zoom here") plt.show() From eb41064cb741eccffa5377a4c71724a1645cbe1a Mon Sep 17 00:00:00 2001 From: mlub Date: Mon, 18 Jul 2016 18:37:40 -0500 Subject: [PATCH 2/2] 2.0 Examples fixes. See #6762 These are fixes for all issues found in axes_grid, color, and event_handling sections on the examples page. axisartist/demo_curvelinear_grid.py - Set linewidth=2.0 and grid zorder=0 so the plotted lines actually visible event_handling/keypress_demo.py - added usage instruction as axes title event_handling/lasso_demo.py - added usage instruction as axes title event_handling/looking_glass.py - added usage instruction as axes title event_handling/resample.py - removed gtk and hardcoded wave file dependencies and just created a sample signal within the script event_handling/trifinder_event_demo.py - zip(l1,l2) call changed to list(zip(l1,l2)) to be python3 compatible event_handling/viewlims.py - The focus box that is supposed to appear in the left axes when user zooms in the right axes wasn't visible. Set linewidth=1.0 --- examples/axes_grid1/demo_colorbar_with_inset_locator.py | 4 ++-- examples/axes_grid1/simple_axesgrid.py | 2 +- examples/event_handling/looking_glass.py | 1 + examples/event_handling/resample.py | 8 +++----- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/examples/axes_grid1/demo_colorbar_with_inset_locator.py b/examples/axes_grid1/demo_colorbar_with_inset_locator.py index 157ab07fb4fd..72a920b402c5 100644 --- a/examples/axes_grid1/demo_colorbar_with_inset_locator.py +++ b/examples/axes_grid1/demo_colorbar_with_inset_locator.py @@ -9,7 +9,7 @@ height="5%", # height : 50% loc=1) -im1 = ax1.imshow([[1, 2], [2, 3]], interpolation='bilinear') +im1 = ax1.imshow([[1, 2], [2, 3]]) plt.colorbar(im1, cax=axins1, orientation="horizontal", ticks=[1, 2, 3]) axins1.xaxis.set_ticks_position("bottom") @@ -26,7 +26,7 @@ # of the legend. you may want to play with the borderpad value and # the bbox_to_anchor coordinate. -im = ax2.imshow([[1, 2], [2, 3]], interpolation='bilinear') +im = ax2.imshow([[1, 2], [2, 3]]) plt.colorbar(im, cax=axins, ticks=[1, 2, 3]) plt.draw() diff --git a/examples/axes_grid1/simple_axesgrid.py b/examples/axes_grid1/simple_axesgrid.py index c96a9f2801f8..b8c45f2aae6d 100644 --- a/examples/axes_grid1/simple_axesgrid.py +++ b/examples/axes_grid1/simple_axesgrid.py @@ -12,6 +12,6 @@ ) for i in range(4): - grid[i].imshow(im, interpolation='bilinear') # The AxesGrid object work as a list of axes. + grid[i].imshow(im) # The AxesGrid object work as a list of axes. plt.show() diff --git a/examples/event_handling/looking_glass.py b/examples/event_handling/looking_glass.py index 8d481fe31a73..8a5c0d0979b0 100644 --- a/examples/event_handling/looking_glass.py +++ b/examples/event_handling/looking_glass.py @@ -12,6 +12,7 @@ line, = ax.plot(x, y, alpha=1.0, clip_path=circ) ax.set_title("Left click and drag to move looking glass") + class EventHandler(object): def __init__(self): fig.canvas.mpl_connect('button_press_event', self.onpress) diff --git a/examples/event_handling/resample.py b/examples/event_handling/resample.py index 0ca5bc88edcd..1b380a06cb96 100644 --- a/examples/event_handling/resample.py +++ b/examples/event_handling/resample.py @@ -32,20 +32,18 @@ def update(self, ax): ax.figure.canvas.draw_idle() # Create a signal -xdata = np.linspace(16,365,365-16) -ydata = np.sin(2*np.pi*xdata/153) + np.cos(2*np.pi*xdata/127); +xdata = np.linspace(16, 365, 365-16) +ydata = np.sin(2*np.pi*xdata/153) + np.cos(2*np.pi*xdata/127) d = DataDisplayDownsampler(xdata, ydata) fig, ax = plt.subplots() # Hook up the line -d.line, = ax.plot(xdata, ydata,'o-') +d.line, = ax.plot(xdata, ydata, 'o-') ax.set_autoscale_on(False) # Otherwise, infinite loop # Connect for changing the view limits ax.callbacks.connect('xlim_changed', d.update) plt.show() - -