|
From: <jd...@us...> - 2008-06-26 20:15:52
|
Revision: 5683
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5683&view=rev
Author: jdh2358
Date: 2008-06-26 13:15:45 -0700 (Thu, 26 Jun 2008)
Log Message:
-----------
cleaned some more examples
Modified Paths:
--------------
trunk/matplotlib/examples/pylab_examples/cohere_demo.py
trunk/matplotlib/examples/pylab_examples/csd_demo.py
trunk/matplotlib/examples/pylab_examples/fill_demo.py
trunk/matplotlib/examples/pylab_examples/hexbin_demo.py
trunk/matplotlib/examples/pylab_examples/histogram_demo.py
trunk/matplotlib/examples/pylab_examples/image_demo.py
Added Paths:
-----------
trunk/matplotlib/lib/mpl_examples
Modified: trunk/matplotlib/examples/pylab_examples/cohere_demo.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/cohere_demo.py 2008-06-26 19:08:48 UTC (rev 5682)
+++ trunk/matplotlib/examples/pylab_examples/cohere_demo.py 2008-06-26 20:15:45 UTC (rev 5683)
@@ -2,36 +2,35 @@
"""
Compute the coherence of two signals
"""
-import numpy as n
+import numpy as np
+import matplotlib.pyplot as plt
-from pylab import figure, show
+# make a little extra space between the subplots
+plt.subplots_adjust(wspace=0.5)
dt = 0.01
-t = n.arange(0, 30, dt)
-Nt = len(t)
-nse1 = n.random.randn(Nt) # white noise 1
-nse2 = n.random.randn(Nt) # white noise 2
-r = n.exp(-t/0.05)
+t = np.arange(0, 30, dt)
+nse1 = np.random.randn(len(t)) # white noise 1
+nse2 = np.random.randn(len(t)) # white noise 2
+r = np.exp(-t/0.05)
-cnse1 = n.convolve(nse1, r)*dt # colored noise 1
-cnse1 = cnse1[:Nt]
-cnse2 = n.convolve(nse2, r)*dt # colored noise 2
-cnse2 = cnse2[:Nt]
+cnse1 = np.convolve(nse1, r, mode='same')*dt # colored noise 1
+cnse2 = np.convolve(nse2, r, mode='same')*dt # colored noise 2
# two signals with a coherent part and a random part
-s1 = 0.01*n.sin(2*n.pi*10*t) + cnse1
-s2 = 0.01*n.sin(2*n.pi*10*t) + cnse2
+s1 = 0.01*np.sin(2*np.pi*10*t) + cnse1
+s2 = 0.01*np.sin(2*np.pi*10*t) + cnse2
-fig = figure()
-ax = fig.add_subplot(211)
-ax.plot(t, s1, 'b-', t, s2, 'g-')
-ax.set_xlim(0,5)
-ax.set_xlabel('time')
-ax.set_ylabel('s1 and s2')
+plt.subplot(211)
+plt.plot(t, s1, 'b-', t, s2, 'g-')
+plt.xlim(0,5)
+plt.xlabel('time')
+plt.ylabel('s1 and s2')
+plt.grid(True)
-ax = fig.add_subplot(212)
-cxy, f = ax.cohere(s1, s2, 256, 1./dt)
+plt.subplot(212)
+cxy, f = plt.cohere(s1, s2, 256, 1./dt)
+plt.ylabel('coherence')
+plt.show()
-show()
-
Modified: trunk/matplotlib/examples/pylab_examples/csd_demo.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/csd_demo.py 2008-06-26 19:08:48 UTC (rev 5682)
+++ trunk/matplotlib/examples/pylab_examples/csd_demo.py 2008-06-26 20:15:45 UTC (rev 5683)
@@ -2,32 +2,35 @@
"""
Compute the cross spectral density of two signals
"""
-from __future__ import division
-from pylab import *
+import numpy as np
+import matplotlib.pyplot as plt
+# make a little extra space between the subplots
+plt.subplots_adjust(wspace=0.5)
+
dt = 0.01
-t = arange(0, 30, dt)
-nse1 = randn(len(t)) # white noise 1
-nse2 = randn(len(t)) # white noise 2
-r = exp(divide(-t,0.05))
+t = np.arange(0, 30, dt)
+nse1 = np.random.randn(len(t)) # white noise 1
+nse2 = np.random.randn(len(t)) # white noise 2
+r = np.exp(-t/0.05)
-cnse1 = convolve(nse1, r, mode=2)*dt # colored noise 1
-cnse1 = cnse1[:len(t)]
-cnse2 = convolve(nse2, r, mode=2)*dt # colored noise 2
-cnse2 = cnse2[:len(t)]
+cnse1 = np.convolve(nse1, r, mode='same')*dt # colored noise 1
+cnse2 = np.convolve(nse2, r, mode='same')*dt # colored noise 2
# two signals with a coherent part and a random part
-s1 = 0.01*sin(2*pi*10*t) + cnse1
-s2 = 0.01*sin(2*pi*10*t) + cnse2
+s1 = 0.01*np.sin(2*np.pi*10*t) + cnse1
+s2 = 0.01*np.sin(2*np.pi*10*t) + cnse2
-subplot(211)
-plot(t, s1, 'b-', t, s2, 'g-')
-xlim(0,5)
-xlabel('time')
-ylabel('s1 and s2')
+plt.subplot(211)
+plt.plot(t, s1, 'b-', t, s2, 'g-')
+plt.xlim(0,5)
+plt.xlabel('time')
+plt.ylabel('s1 and s2')
+plt.grid(True)
-subplot(212)
-cxy, f = csd(s1, s2, 256, 1/dt)
-show()
+plt.subplot(212)
+cxy, f = plt.csd(s1, s2, 256, 1./dt)
+plt.ylabel('CSD (db)')
+plt.show()
Modified: trunk/matplotlib/examples/pylab_examples/fill_demo.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/fill_demo.py 2008-06-26 19:08:48 UTC (rev 5682)
+++ trunk/matplotlib/examples/pylab_examples/fill_demo.py 2008-06-26 20:15:45 UTC (rev 5683)
@@ -1,8 +1,10 @@
#!/usr/bin/env python
-from pylab import *
-t = arange(0.0, 1.01, 0.01)
-s = sin(2*2*pi*t)
+import numpy as np
+import matplotlib.pyplot as plt
-fill(t, s*exp(-5*t), 'r')
-grid(True)
-show()
+t = np.arange(0.0, 1.01, 0.01)
+s = np.sin(2*2*np.pi*t)
+
+plt.fill(t, s*np.exp(-5*t), 'r')
+plt.grid(True)
+plt.show()
Modified: trunk/matplotlib/examples/pylab_examples/hexbin_demo.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/hexbin_demo.py 2008-06-26 19:08:48 UTC (rev 5682)
+++ trunk/matplotlib/examples/pylab_examples/hexbin_demo.py 2008-06-26 20:15:45 UTC (rev 5683)
@@ -1,13 +1,12 @@
-'''
+"""
hexbin is an axes method or pyplot function that is essentially
a pcolor of a 2-D histogram with hexagonal cells. It can be
much more informative than a scatter plot; in the first subplot
below, try substituting 'scatter' for 'hexbin'.
-'''
+"""
-from matplotlib.pyplot import *
import numpy as np
-
+import matplotlib.pyplot as plt
n = 100000
x = np.random.standard_normal(n)
y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n)
@@ -16,19 +15,20 @@
ymin = y.min()
ymax = y.max()
-subplot(121)
-hexbin(x,y)
-axis([xmin, xmax, ymin, ymax])
-title("Hexagon binning")
-cb = colorbar()
+plt.subplots_adjust(hspace=0.5)
+plt.subplot(121)
+plt.hexbin(x,y)
+plt.axis([xmin, xmax, ymin, ymax])
+plt.title("Hexagon binning")
+cb = plt.colorbar()
cb.set_label('counts')
-subplot(122)
-hexbin(x,y,bins='log')
-axis([xmin, xmax, ymin, ymax])
-title("With a log color scale")
-cb = colorbar()
+plt.subplot(122)
+plt.hexbin(x,y,bins='log')
+plt.axis([xmin, xmax, ymin, ymax])
+plt.title("With a log color scale")
+cb = plt.colorbar()
cb.set_label('log10(N)')
-show()
+plt.show()
Modified: trunk/matplotlib/examples/pylab_examples/histogram_demo.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/histogram_demo.py 2008-06-26 19:08:48 UTC (rev 5682)
+++ trunk/matplotlib/examples/pylab_examples/histogram_demo.py 2008-06-26 20:15:45 UTC (rev 5683)
@@ -1,23 +1,22 @@
#!/usr/bin/env python
-import pylab as P
+import numpy as np
+import matplotlib.mlab as mlab
+import matplotlib.pyplot as plt
mu, sigma = 100, 15
-x = mu + sigma*P.randn(10000)
+x = mu + sigma*np.random.randn(10000)
# the histogram of the data
-n, bins, patches = P.hist(x, 50, normed=1)
-P.setp(patches, 'facecolor', 'g', 'alpha', 0.75)
+n, bins, patches = plt.hist(x, 50, normed=1, facecolor='green', alpha=0.75)
# add a 'best fit' line
-y = P.normpdf( bins, mu, sigma)
-l = P.plot(bins, y, 'r--')
-P.setp(l, 'linewidth', 1)
+y = mlab.normpdf( bins, mu, sigma)
+l = plt.plot(bins, y, 'r--', linewidth=1)
-P.xlabel('Smarts')
-P.ylabel('Probability')
-P.title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$')
-P.axis([40, 160, 0, 0.03])
-P.grid(True)
+plt.xlabel('Smarts')
+plt.ylabel('Probability')
+plt.title(r'$\mathrm{Histogram\ of\ IQ:}\ \mu=100,\ \sigma=15$')
+plt.axis([40, 160, 0, 0.03])
+plt.grid(True)
-#P.savefig('histogram_demo',dpi=72)
-P.show()
+plt.show()
Modified: trunk/matplotlib/examples/pylab_examples/image_demo.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/image_demo.py 2008-06-26 19:08:48 UTC (rev 5682)
+++ trunk/matplotlib/examples/pylab_examples/image_demo.py 2008-06-26 20:15:45 UTC (rev 5683)
@@ -1,16 +1,18 @@
#!/usr/bin/env python
-from pylab import *
+import numpy as np
+import matplotlib.cm as cm
+import matplotlib.mlab as mlab
+import matplotlib.pyplot as plt
delta = 0.025
-x = y = arange(-3.0, 3.0, delta)
-X, Y = meshgrid(x, y)
-Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
-Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
+x = y = np.arange(-3.0, 3.0, delta)
+X, Y = np.meshgrid(x, y)
+Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
+Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
Z = Z2-Z1 # difference of Gaussians
-im = imshow(Z, interpolation='bilinear', cmap=cm.gray,
- origin='lower', extent=[-3,3,-3,3])
+im = plt.imshow(Z, interpolation='bilinear', cmap=cm.gray,
+ origin='lower', extent=[-3,3,-3,3])
-savefig('image_demo')
-show()
+plt.show()
Added: trunk/matplotlib/lib/mpl_examples
===================================================================
--- trunk/matplotlib/lib/mpl_examples (rev 0)
+++ trunk/matplotlib/lib/mpl_examples 2008-06-26 20:15:45 UTC (rev 5683)
@@ -0,0 +1 @@
+link ../examples
\ No newline at end of file
Property changes on: trunk/matplotlib/lib/mpl_examples
___________________________________________________________________
Name: svn:special
+ *
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|