From: <ry...@us...> - 2009-02-12 21:24:39
|
Revision: 6910 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6910&view=rev Author: ryanmay Date: 2009-02-12 21:24:36 +0000 (Thu, 12 Feb 2009) Log Message: ----------- Merged revisions 6906-6907,6909 via svnmerge from https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/branches/v0_98_5_maint ........ r6906 | ryanmay | 2009-02-12 14:05:10 -0600 (Thu, 12 Feb 2009) | 1 line Add a demo for getting notified of an Axes' change in view limits. ........ r6907 | ryanmay | 2009-02-12 14:06:50 -0600 (Thu, 12 Feb 2009) | 1 line Remove trailing whitespace. ........ r6909 | ryanmay | 2009-02-12 15:20:09 -0600 (Thu, 12 Feb 2009) | 1 line Make viewlims demo more interesting by using events to regenerate a fractal. ........ Modified Paths: -------------- trunk/matplotlib/doc/users/event_handling.rst Added Paths: ----------- trunk/matplotlib/examples/event_handling/viewlims.py Property Changed: ---------------- trunk/matplotlib/ Property changes on: trunk/matplotlib ___________________________________________________________________ Modified: svnmerge-integrated - /branches/v0_91_maint:1-6428 /branches/v0_98_5_maint:1-6892 + /branches/v0_91_maint:1-6428 /branches/v0_98_5_maint:1-6909 Modified: svn:mergeinfo - /branches/v0_91_maint:5753-5771 /branches/v0_98_5_maint:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891 + /branches/v0_91_maint:5753-5771 /branches/v0_98_5_maint:6581,6585,6587,6589-6609,6614,6616,6625,6652,6660-6662,6672-6673,6714-6715,6717-6732,6752-6754,6761-6773,6781,6792,6800,6802,6805,6809,6811,6822,6827,6850,6854,6856,6859,6861-6873,6883-6884,6886,6890-6891,6906-6909 Modified: trunk/matplotlib/doc/users/event_handling.rst =================================================================== --- trunk/matplotlib/doc/users/event_handling.rst 2009-02-12 21:20:09 UTC (rev 6909) +++ trunk/matplotlib/doc/users/event_handling.rst 2009-02-12 21:24:36 UTC (rev 6910) @@ -552,11 +552,4 @@ fig.canvas.mpl_connect('pick_event', onpick) - plt.show() - - - - - - - + plt.show() Copied: trunk/matplotlib/examples/event_handling/viewlims.py (from rev 6909, branches/v0_98_5_maint/examples/event_handling/viewlims.py) =================================================================== --- trunk/matplotlib/examples/event_handling/viewlims.py (rev 0) +++ trunk/matplotlib/examples/event_handling/viewlims.py 2009-02-12 21:24:36 UTC (rev 6910) @@ -0,0 +1,79 @@ +# Creates two identical panels. Zooming in on the right panel will show +# a rectangle in the first panel, denoting the zoomed region. +import numpy as np +import matplotlib.pyplot as plt +from matplotlib.patches import Rectangle + +# We just subclass Rectangle so that it can be called with an Axes +# instance, causing the rectangle to update its shape to match the +# bounds of the Axes +class UpdatingRect(Rectangle): + def __call__(self, ax): + self.set_bounds(*ax.viewLim.bounds) + ax.figure.canvas.draw_idle() + +# A class that will regenerate a fractal set as we zoom in, so that you +# can actually see the increasing detail. A box in the left panel will show +# the area to which we are zoomed. +class MandlebrotDisplay(object): + def __init__(self, h=500, w=500, niter=50, radius=2., power=2): + self.height = h + self.width = w + self.niter = niter + self.radius = radius + self.power = power + + def __call__(self, xstart, xend, ystart, yend): + self.x = np.linspace(xstart, xend, self.width) + self.y = np.linspace(ystart, yend, self.height).reshape(-1,1) + c = self.x + 1.0j * self.y + threshold_time = np.zeros((self.height, self.width)) + z = np.zeros(threshold_time.shape, dtype=np.complex) + mask = np.ones(threshold_time.shape, dtype=np.bool) + for i in xrange(self.niter): + z[mask] = z[mask]**self.power + c[mask] + mask = (np.abs(z) < self.radius) + threshold_time += mask + return threshold_time + + def ax_update(self, ax): + ax.set_autoscale_on(False) # Otherwise, infinite loop + + #Get the number of points from the number of pixels in the window + dims = ax.axesFrame.get_window_extent().bounds + self.width = int(dims[2] + 0.5) + self.height = int(dims[2] + 0.5) + + #Get the range for the new area + xstart,ystart,xdelta,ydelta = ax.viewLim.bounds + xend = xstart + xdelta + yend = ystart + ydelta + + # Update the image object with our new data and extent + im = ax.images[-1] + im.set_data(self.__call__(xstart, xend, ystart, yend)) + im.set_extent((xstart, xend, ystart, yend)) + ax.figure.canvas.draw_idle() + +md = MandlebrotDisplay() +Z = md(-2., 0.5, -1.25, 1.25) + +fig = plt.figure() +ax1 = fig.add_subplot(1, 2, 1) +ax1.imshow(Z, origin='lower', extent=(md.x.min(), md.x.max(), md.y.min(), md.y.max())) + +ax2 = fig.add_subplot(1, 2, 2) +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.set_bounds(*ax2.viewLim.bounds) +ax1.add_patch(rect) + +# Connect for changing the view limits +ax2.callbacks.connect('xlim_changed', rect) +ax2.callbacks.connect('ylim_changed', rect) + +ax2.callbacks.connect('xlim_changed', md.ax_update) +ax2.callbacks.connect('ylim_changed', md.ax_update) + +plt.show() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |