Revision: 7499
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=7499&view=rev
Author:   jdh2358
Date:     2009-08-18 05:15:21 +0000 (Tue, 18 Aug 2009)

Log Message:
-----------
added looking glass demo

Added Paths:
-----------
    branches/v0_99_maint/examples/event_handling/looking_glass.py

Added: branches/v0_99_maint/examples/event_handling/looking_glass.py
===================================================================
--- branches/v0_99_maint/examples/event_handling/looking_glass.py               
                (rev 0)
+++ branches/v0_99_maint/examples/event_handling/looking_glass.py       
2009-08-18 05:15:21 UTC (rev 7499)
@@ -0,0 +1,47 @@
+import numpy as np
+import matplotlib.pyplot as plt
+import matplotlib.patches as patches
+x, y = np.random.rand(2, 200)
+
+fig = plt.figure()
+ax = fig.add_subplot(111)
+circ = patches.Circle( (0.5, 0.5), 0.25, alpha=0.8, fc='yellow')
+ax.add_patch(circ)
+
+
+ax.plot(x, y, alpha=0.2)
+line, = ax.plot(x, y, alpha=1.0, clip_path=circ)
+
+class EventHandler:
+   def __init__(self):
+       fig.canvas.mpl_connect('button_press_event', self.onpress)
+       fig.canvas.mpl_connect('button_release_event', self.onrelease)
+       fig.canvas.mpl_connect('motion_notify_event', self.onmove)
+       self.x0, self.y0 = circ.center
+       self.pressevent = None
+
+   def onpress(self, event):
+      if event.inaxes!=ax:
+         return
+
+      if not circ.contains(event):
+         return
+
+      self.pressevent = event
+
+   def onrelease(self, event):
+      self.pressevent = None
+      self.x0, self.y0 = circ.center
+
+   def onmove(self, event):
+      if self.pressevent is None or event.inaxes!=self.pressevent.inaxes:
+         return
+
+      dx = event.xdata - self.pressevent.xdata
+      dy = event.ydata - self.pressevent.ydata
+      circ.center = self.x0 + dx, self.y0 + dy
+      line.set_clip_path(circ)
+      fig.canvas.draw()
+
+handler = EventHandler()
+plt.show()


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to