Revision: 6336
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6336&view=rev
Author:   jdh2358
Date:     2008-10-26 14:33:36 +0000 (Sun, 26 Oct 2008)

Log Message:
-----------
added glass dots skel

Modified Paths:
--------------
    trunk/py4science/examples/glass_dots1.py
    trunk/py4science/examples/glass_dots2.py

Added Paths:
-----------
    trunk/py4science/examples/glass_dots1_skel.py

Modified: trunk/py4science/examples/glass_dots1.py
===================================================================
--- trunk/py4science/examples/glass_dots1.py    2008-10-25 07:06:53 UTC (rev 
6335)
+++ trunk/py4science/examples/glass_dots1.py    2008-10-26 14:33:36 UTC (rev 
6336)
@@ -6,10 +6,9 @@
 See L. Glass. 'Moire effect from random dots' Nature 223, 578580 (1969).
 """
 import cmath
-from numpy import cos, sin, pi, matrix
-import numpy as npy
+import numpy as np
 import numpy.linalg as linalg
-from pylab import figure, show
+import matplotlib.pyplot as plt
 
 
 def myeig(M):
@@ -18,10 +17,16 @@
 
     Solve quadratic:
 
-      lamba^2 - tau*lambda + Delta = 0
+      lamba^2 - tau*lambda +/- Delta = 0
 
     where tau = trace(M) and Delta = Determinant(M)
-    
+
+    if M = | a b |
+           | c d |
+
+    the trace is a+d and the determinant is a*d-b*c
+
+    Return value is lambda1, lambda2
     """
 
     a,b = M[0,0], M[0,1]
@@ -32,31 +37,29 @@
     lambda1 = (tau + cmath.sqrt(tau**2 - 4*delta))/2.
     lambda2 = (tau - cmath.sqrt(tau**2 - 4*delta))/2.
     return lambda1, lambda2
-    
+
 # 2000 random x,y points in the interval[-0.5 ... 0.5]
-X1 = matrix(npy.random.rand(2,2000)
-            )-0.5
+X1 = np.random.rand(2,2000)-0.5
 
-name =  'saddle'
-sx, sy, angle = 1.05, 0.95, 0.
+#name =  'saddle'
+#sx, sy, angle = 1.05, 0.95, 0.
 
-#name = 'center'
-#sx, sy, angle = 1., 1., 2.5
+name = 'center'
+sx, sy, angle = 1., 1., 2.5
 
 #name= 'stable focus'  # spiral
 #sx, sy, angle = 0.95, 0.95, 2.5
 
-theta = angle * pi/180.
+theta = angle * cmath.pi/180.
 
+S = np.array([[sx, 0],
+              [0, sy]])
 
-S = matrix([[sx, 0],
-            [0, sy]])
+R = np.array([[np.cos(theta),  -np.sin(theta)],
+              [np.sin(theta), np.cos(theta)],])
 
-R = matrix([[cos(theta),  -sin(theta)],
-            [sin(theta), cos(theta)],])
+M = np.dot(S, R)  # rotate then stretch
 
-M = S*R  # rotate then stretch
-
 # compute the eigenvalues using numpy linear algebra
 vals, vecs = linalg.eig(M)
 print 'numpy eigenvalues', vals
@@ -66,17 +69,17 @@
 print 'analytic eigenvalues', avals
 
 # transform X1 by the matrix
-X2 = M*X1
+X2 = np.dot(M, X1)
 
 # plot the original x,y as green dots and the transformed x, y as red
 # dots
-fig = figure()
+fig = plt.figure()
 ax = fig.add_subplot(111)
 
-x1 = X1[0].flat
-y1 = X1[1].flat
-x2 = X2[0].flat
-y2 = X2[1].flat
+x1 = X1[0]
+y1 = X1[1]
+x2 = X2[0]
+y2 = X2[1]
 
 ax = fig.add_subplot(111)
 line1, line2 = ax.plot(x1, y1, 'go', x2, y2, 'ro', markersize=2)
@@ -85,4 +88,4 @@
 
 fig.savefig('glass_dots1.png', dpi=100)
 fig.savefig('glass_dots1.eps', dpi=100)
-show()
+plt.show()

Added: trunk/py4science/examples/glass_dots1_skel.py
===================================================================
--- trunk/py4science/examples/glass_dots1_skel.py                               
(rev 0)
+++ trunk/py4science/examples/glass_dots1_skel.py       2008-10-26 14:33:36 UTC 
(rev 6336)
@@ -0,0 +1,80 @@
+"""
+Moire patterns from random dot fields
+
+http://en.wikipedia.org/wiki/Moir%C3%A9_pattern
+
+See L. Glass. 'Moire effect from random dots' Nature 223, 578580 (1969).
+"""
+import cmath
+import numpy as np
+import numpy.linalg as linalg
+import matplotlib.pyplot as plt
+
+# search for TODO to find the places you need to fix
+TODO = None
+
+def myeig(M):
+    """
+    compute eigen values and eigenvectors analytically
+
+    Solve quadratic:
+
+      lamba^2 - tau*lambda +/- Delta = 0
+
+    where tau = trace(M) and Delta = Determinant(M)
+
+    if M = | a b |
+           | c d |
+
+    the trace is a+d and the determinant is a*d-b*c
+
+    Return value is lambda1, lambda2
+
+    Return value is lambda1, lambda2
+    """
+    # TODO : compute the real values here.  0, 1 is just a place holder
+    return 0, 1
+
+# Generate and shape (2000,2) random x,y points in the
+# interval [-0.5 ... 0.5]
+X1 = TODO
+
+# these are the scaling factor sx, the scaling factor sy, and the
+# rotation angle 0
+name =  'saddle'
+sx, sy, angle = 1.05, 0.95, 0.
+
+# OPTIONAL: try and find other sx, sy, theta for other kinds of nodes:
+# stable node, unstable node, center, spiral, saddle
+
+# convert theta to radians: theta = angle * pi/180
+theta = TODO
+
+# Create a 2D scaling array
+# S = | sx 0  |
+#     | 0  sy |
+S = TODO
+
+# create a 2D rotation array
+# R = | cos(theta)   -sin(theta) |
+#     | sin(theta)    cos(theta) |
+R = TODO
+
+# do a matrix multiply M = S x R where x is *matrix* multiplication
+M = TODO
+
+# compute the eigenvalues using numpy linear algebra
+vals, vecs = linalg.eig(M)
+print 'numpy eigenvalues', vals
+
+# compare with the analytic values from myeig
+avals = myeig(M)
+print 'analytic eigenvalues', avals
+
+# transform X1 by the matrix
+# X2 = M x X1  where x is *matrix* multiplication
+X2 = np.dot(M, X1)
+
+# plot the original x,y as green dots and the transformed x, y as red
+# dots
+TODO

Modified: trunk/py4science/examples/glass_dots2.py
===================================================================
--- trunk/py4science/examples/glass_dots2.py    2008-10-25 07:06:53 UTC (rev 
6335)
+++ trunk/py4science/examples/glass_dots2.py    2008-10-26 14:33:36 UTC (rev 
6336)
@@ -1,4 +1,4 @@
-import numpy as npy
+import numpy as np
 import numpy.linalg as linalg
 from pylab import figure, show
 
@@ -12,15 +12,15 @@
         self.axes = axes
         self.canvas = axes.figure.canvas
         self.canvas.mpl_connect('button_press_event', self.press)
-        self.canvas.mpl_connect('button_release_event', self.release)        
-        self.canvas.mpl_connect('motion_notify_event', self.move)        
+        self.canvas.mpl_connect('button_release_event', self.release)
+        self.canvas.mpl_connect('motion_notify_event', self.move)
 
-        X1 = self.X1 = npy.matrix(npy.random.rand(2,2000))-0.5
+        X1 = self.X1 = np.random.rand(2,2000)-0.5
 
-        x1 = X1[0].flat
-        y1 = X1[1].flat
-        x2 = X1[0].flat # no transformation yet
-        y2 = X1[1].flat
+        x1 = X1[0]
+        y1 = X1[1]
+        x2 = X1[0] # no transformation yet
+        y2 = X1[1]
         self.line1, self.line2 = ax.plot(x1, y1,'go', x2, y2, 'ro', 
markersize=2)
         self.xlast = None
         self.ylast = None
@@ -37,37 +37,37 @@
         self.xlast = None
         self.ylast = None
         self.draw()
-        
+
     def draw(self):
         sx, sy, theta = self.sx, self.sy, self.theta
-        a =  sx*npy.cos(theta)
-        b = -sx*npy.sin(theta)
-        c =  sy*npy.sin(theta)
-        d =  sy*npy.cos(theta)
-        M =  npy.matrix([[a,b],[c,d]])
+        a =  sx*np.cos(theta)
+        b = -sx*np.sin(theta)
+        c =  sy*np.sin(theta)
+        d =  sy*np.cos(theta)
+        M =  np.array([[a,b],[c,d]])
 
-        X2 = M*self.X1        
-        x2 = X2[0].flat
-        y2 = X2[1].flat
+        X2 = np.dot(M, self.X1)
+        x2 = X2[0]
+        y2 = X2[1]
         self.line2.set_data(x2,y2)
 
         self.canvas.draw()
-        
+
     def move(self, event):
 
         if not event.inaxes: return    # not over axes
         if self.xlast is None: return  # no initial data
         if not event.button: return    # no button press
-        
+
         dx = event.xdata - self.xlast
-        dy = event.ydata - self.ylast        
+        dy = event.ydata - self.ylast
 
         if event.button==1:
             self.theta += dx
         elif event.button==3:
             self.sx += dx
             self.sy += dy
-            
+
         self.title.set_text('sx=%1.2f, sy=%1.2f, theta=%1.2f'%(self.sx, 
self.sy, self.theta))
         self.draw()
         self.xlast = event.xdata
@@ -75,9 +75,9 @@
 
 
 
-        
-from pylab import subplot, show        
-fig = figure()
+
+import matplotlib.pyplot as plt
+fig = plt.figure()
 ax = fig.add_subplot(111)
 t = Transformer(ax)
-show()
+plt.show()


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

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to