[Scipy-svn] r5101 - in scipy-docs/trunk: . source source/tutorial source/tutorial/examples

scipy-svn@scip... scipy-svn@scip...
Thu Nov 13 18:37:27 CST 2008


Author: ptvirtan
Date: 2008-11-13 18:36:56 -0600 (Thu, 13 Nov 2008)
New Revision: 5101

Modified:
   scipy-docs/trunk/Makefile
   scipy-docs/trunk/source/conf.py
   scipy-docs/trunk/source/spatial.rst
   scipy-docs/trunk/source/tutorial/examples/10.2.5
   scipy-docs/trunk/source/tutorial/examples/6.1
   scipy-docs/trunk/source/tutorial/examples/6.2
   scipy-docs/trunk/source/tutorial/examples/6.3
   scipy-docs/trunk/source/tutorial/examples/6.4
   scipy-docs/trunk/source/tutorial/index.rst
Log:
Fix plots in tutorial: generate all figures from the source code, using matplotlib.

Modified: scipy-docs/trunk/Makefile
===================================================================
--- scipy-docs/trunk/Makefile	2008-11-14 00:36:33 UTC (rev 5100)
+++ scipy-docs/trunk/Makefile	2008-11-14 00:36:56 UTC (rev 5101)
@@ -108,5 +108,5 @@
 	@echo "Link check complete; look for any errors in the above output " \
 	      "or in build/linkcheck/output.txt."
 
-.PHONY: help clean upload dist generate ext html pickle web htmlhelp latex \
+.PHONY: help clean upload dist generate html pickle web htmlhelp latex \
 	coverage changes linkcheck

Modified: scipy-docs/trunk/source/conf.py
===================================================================
--- scipy-docs/trunk/source/conf.py	2008-11-14 00:36:33 UTC (rev 5100)
+++ scipy-docs/trunk/source/conf.py	2008-11-14 00:36:56 UTC (rev 5101)
@@ -69,7 +69,7 @@
 
 # If true, sectionauthor and moduleauthor directives will be shown in the
 # output. They are ignored by default.
-#show_authors = False
+show_authors = True
 
 # The name of the Pygments (syntax highlighting) style to use.
 pygments_style = 'sphinx'
@@ -231,3 +231,11 @@
 coverage_ignore_c_items = {}
 
 
+#------------------------------------------------------------------------------
+# Plot
+#------------------------------------------------------------------------------
+plot_pre_code = """
+import numpy
+numpy.random.seed(123)
+"""
+plot_output_dir = '_static/plot_directive'

Modified: scipy-docs/trunk/source/spatial.rst
===================================================================
--- scipy-docs/trunk/source/spatial.rst	2008-11-14 00:36:33 UTC (rev 5100)
+++ scipy-docs/trunk/source/spatial.rst	2008-11-14 00:36:56 UTC (rev 5101)
@@ -6,5 +6,9 @@
 
    This documentation is work-in-progress and unorganized.
 
+.. toctree::
+
+   spatial.distance
+
 .. automodule:: scipy.spatial
    :members:

Modified: scipy-docs/trunk/source/tutorial/examples/10.2.5
===================================================================
--- scipy-docs/trunk/source/tutorial/examples/10.2.5	2008-11-14 00:36:33 UTC (rev 5100)
+++ scipy-docs/trunk/source/tutorial/examples/10.2.5	2008-11-14 00:36:56 UTC (rev 5101)
@@ -1,3 +1,7 @@
+from numpy import *
+from scipy import linalg
+import matplotlib.pyplot as plt
+
 c1,c2= 5.0,2.0
 i = r_[1:11]
 xi = 0.1*i
@@ -2,5 +6,5 @@
 yi = c1*exp(-xi)+c2*xi
-zi = yi + 0.05*max(yi)*randn(len(yi))
+zi = yi + 0.05*max(yi)*random.randn(len(yi))
 
-A = c_[exp(-xi)[:,NewAxis],xi[:,NewAxis]]
+A = c_[exp(-xi)[:,newaxis],xi[:,newaxis]]
 c,resid,rank,sigma = linalg.lstsq(A,zi)
@@ -10,8 +14,8 @@
 xi2 = r_[0.1:1.0:100j]
 yi2 = c[0]*exp(-xi2) + c[1]*xi2
 
-xplt.plot(xi,zi,'x',xi2,yi2)
-xplt.limits(0,1.1,3.0,5.5)
-xplt.xlabel('x_i')
-xplt.title('Data fitting with linalg.lstsq')
-xplt.eps('lstsq_fit')
+plt.plot(xi,zi,'x',xi2,yi2)
+plt.axis([0,1.1,3.0,5.5])
+plt.xlabel('$x_i$')
+plt.title('Data fitting with linalg.lstsq')
+plt.show()

Modified: scipy-docs/trunk/source/tutorial/examples/6.1
===================================================================
--- scipy-docs/trunk/source/tutorial/examples/6.1	2008-11-14 00:36:33 UTC (rev 5100)
+++ scipy-docs/trunk/source/tutorial/examples/6.1	2008-11-14 00:36:56 UTC (rev 5101)
@@ -1,18 +1,10 @@
+>>> from numpy import *
+>>> from scipy import interpolate
+
 >>> x = arange(0,10)
 >>> y = exp(-x/3.0)
->>> f = interpolate.linear_1d(x,y)
->>> help(f)
-Instance of class:  linear_1d
+>>> f = interpolate.interp1d(x, y)
 
- <name>(x_new)
-
-Find linearly interpolated y_new = <name>(x_new).
-
-Inputs:        
-  x_new -- New independent variables.
-
-Outputs:
-  y_new -- Linearly interpolated values corresponding to x_new.
-
 >>> xnew = arange(0,9,0.1)
->>> xplt.plot(x,y,'x',xnew,f(xnew),'.')
+>>> import matplotlib.pyplot as plt
+>>> plt.plot(x,y,'o',xnew,f(xnew),'-')

Modified: scipy-docs/trunk/source/tutorial/examples/6.2
===================================================================
--- scipy-docs/trunk/source/tutorial/examples/6.2	2008-11-14 00:36:33 UTC (rev 5100)
+++ scipy-docs/trunk/source/tutorial/examples/6.2	2008-11-14 00:36:56 UTC (rev 5101)
@@ -8,16 +8,19 @@
 >>> tck = interpolate.splrep(x,y,s=0)
 >>> xnew = arange(0,2*pi,pi/50)
 >>> ynew = interpolate.splev(xnew,tck,der=0)
+
+>>> plt.figure()
 >>> plt.plot(x,y,'x',xnew,ynew,xnew,sin(xnew),x,y,'b')
->>> #plt.legend(['Linear','Cubic Spline', 'True'])
+>>> plt.legend(['Linear','Cubic Spline', 'True'])
 >>> plt.axis([-0.05,6.33,-1.05,1.05])
 >>> plt.title('Cubic-spline interpolation')
 >>> plt.show()
 
 >>> # Derivative of spline
 >>> yder = interpolate.splev(xnew,tck,der=1)
->>> plt.plot(xnew,yder,xnew,cos(xnew),'|')
->>> #plt.legend(['Cubic Spline', 'True'])
+>>> plt.figure()
+>>> plt.plot(xnew,yder,xnew,cos(xnew),'--')
+>>> plt.legend(['Cubic Spline', 'True'])
 >>> plt.axis([-0.05,6.33,-1.05,1.05])
 >>> plt.title('Derivative estimation from spline')
 >>> plt.show()
@@ -32,8 +35,9 @@
 >>>     return out
 >>>
 >>> yint = integ(xnew,tck)
->>> plt.plot(xnew,yint,xnew,-cos(xnew),'|')
->>> #plt.legend(['Cubic Spline', 'True'])
+>>> plt.figure()
+>>> plt.plot(xnew,yint,xnew,-cos(xnew),'--')
+>>> plt.legend(['Cubic Spline', 'True'])
 >>> plt.axis([-0.05,6.33,-1.05,1.05])
 >>> plt.title('Integral estimation from spline')
 >>> plt.show()
@@ -49,8 +53,9 @@
 >>> tck,u = interpolate.splprep([x,y],s=0)
 >>> unew = arange(0,1.01,0.01)
 >>> out = interpolate.splev(unew,tck)
+>>> plt.figure()
 >>> plt.plot(x,y,'x',out[0],out[1],sin(2*pi*unew),cos(2*pi*unew),x,y,'b')
->>> #plt.legend(['Linear','Cubic Spline', 'True'],['b-x','m','r'])
+>>> plt.legend(['Linear','Cubic Spline', 'True'])
 >>> plt.axis([-1.05,1.05,-1.05,1.05])
 >>> plt.title('Spline of parametrically-defined curve')
 >>> plt.show()

Modified: scipy-docs/trunk/source/tutorial/examples/6.3
===================================================================
--- scipy-docs/trunk/source/tutorial/examples/6.3	2008-11-14 00:36:33 UTC (rev 5100)
+++ scipy-docs/trunk/source/tutorial/examples/6.3	2008-11-14 00:36:56 UTC (rev 5101)
@@ -1,14 +1,24 @@
+>>> from numpy import *
+>>> from scipy import interpolate
+>>> import matplotlib.pyplot as plt
+
 >>> # Define function over sparse 20x20 grid
 >>> x,y = mgrid[-1:1:20j,-1:1:20j]
 >>> z = (x+y)*exp(-6.0*(x*x+y*y))
->>> xplt.surf(z,x,y,shade=1,palette='rainbow')
->>> xplt.title3("Sparsely sampled function.")
->>> xplt.eps("2d_func")
 
+>>> plt.figure()
+>>> plt.pcolor(x,y,z)
+>>> plt.colorbar()
+>>> plt.title("Sparsely sampled function.")
+>>> plt.show()
+
 >>> # Interpolate function over new 70x70 grid
 >>> xnew,ynew = mgrid[-1:1:70j,-1:1:70j]
 >>> tck = interpolate.bisplrep(x,y,z,s=0)
 >>> znew = interpolate.bisplev(xnew[:,0],ynew[0,:],tck)
->>> xplt.surf(znew,xnew,ynew,shade=1,palette='rainbow')
->>> xplt.title3("Interpolated function.")
->>> xplt.eps("2d_interp")
+
+>>> plt.figure()
+>>> plt.pcolor(xnew,ynew,znew)
+>>> plt.colorbar()
+>>> plt.title("Interpolated function.")
+>>> plt.show()

Modified: scipy-docs/trunk/source/tutorial/examples/6.4
===================================================================
--- scipy-docs/trunk/source/tutorial/examples/6.4	2008-11-14 00:36:33 UTC (rev 5100)
+++ scipy-docs/trunk/source/tutorial/examples/6.4	2008-11-14 00:36:56 UTC (rev 5101)
@@ -1,16 +1,25 @@
->>> image = lena().astype(Float32)
->>> derfilt = array([1.0,-2,1.0],Float32)
+>>> from numpy import *
+>>> from scipy import signal, misc
+>>> import matplotlib.pyplot as plt
+
+>>> image = misc.lena().astype(float32)
+>>> derfilt = array([1.0,-2,1.0],float32)
 >>> ck = signal.cspline2d(image,8.0)
 >>> deriv = signal.sepfir2d(ck, derfilt, [1]) + \
 >>>         signal.sepfir2d(ck, [1], derfilt)
 >>> 
 >>> ## Alternatively we could have done:
->>> ## laplacian = array([[0,1,0],[1,-4,1],[0,1,0]],Float32)
+>>> ## laplacian = array([[0,1,0],[1,-4,1],[0,1,0]],float32)
 >>> ## deriv2 = signal.convolve2d(ck,laplacian,mode='same',boundary='symm')
->>> 
->>> xplt.imagesc(image[::-1]) # flip image so it looks right-side up.
->>> xplt.title('Original image')
->>> xplt.eps('lena_image')
->>> xplt.imagesc(deriv[::-1])
->>> xplt.title('Output of spline edge filter')
->>> xplt.eps('lena_edge')
+
+>>> plt.figure()
+>>> plt.imshow(image)
+>>> plt.gray()
+>>> plt.title('Original image')
+>>> plt.show()
+
+>>> plt.figure()
+>>> plt.imshow(deriv)
+>>> plt.gray()
+>>> plt.title('Output of spline edge filter')
+>>> plt.show()

Modified: scipy-docs/trunk/source/tutorial/index.rst
===================================================================
--- scipy-docs/trunk/source/tutorial/index.rst	2008-11-14 00:36:33 UTC (rev 5100)
+++ scipy-docs/trunk/source/tutorial/index.rst	2008-11-14 00:36:56 UTC (rev 5101)
@@ -841,15 +841,15 @@
 used to find the best-fit parameters :math:`\hat{A},\,\hat{k},\,\hat{\theta}` . This is shown in the following example and a plot of the results is
 shown in Figure `1 <#fig-least-squares-fit>`__ . 
 
+.. _`fig:least_squares_fit`:
+
 .. plot:: source/tutorial/examples/5.7
    :include-source:
    :doctest-format:
    :align: center
 
-.. **Figure 1**  Least-square fitting to noisy data using 
-.. :obj:`scipy.optimize.leastsq`
-..   
-.. .. _`fig:least_squares_fit`:
+.. XXX: **Figure 1**  Least-square fitting to noisy data using 
+.. XXX: :obj:`scipy.optimize.leastsq`
 
 
 Scalar function minimizers
@@ -963,25 +963,24 @@
 create a function based on fixed data points which can be evaluated
 anywhere within the domain defined by the given data using linear
 interpolation. An instance of this class is created by passing the 1-d
-vectors comprising the data. The instance of this class defines a *__call__* method and can therefore by treated like a function which interpolates
-between known data values to obtain unknown values (it even has a
-docstring for help). Behavior at the boundary can be specified at
-instantiation time. The following example demonstrates it's use. 
+vectors comprising the data. The instance of this class defines a
+*__call__* method and can therefore by treated like a function which
+interpolates between known data values to obtain unknown values (it
+even has a docstring for help). Behavior at the boundary can be
+specified at instantiation time. The following example demonstrates
+it's use.
 
+.. _`fig:inter_1d`:
 
-.. literalinclude:: examples/6.1
-Figure shows the result: 
-
-.. figure:: inter_1d.epsi
+.. plot:: source/tutorial/examples/6.1
+   :doctest-format:
+   :include-source:
    :align: center
 
-   **Figure 2**  One-dimensional interpolation using the class :obj:`interpolate.linear_1d` 
-   
-   .. _`fig:inter_1d`:
+.. **Figure 2**  One-dimensional interpolation using the 
+   class :obj:`interpolate.linear_1d` 
 
 
-
-
 Spline interpolation in 1-d (interpolate.splXXX)
 ------------------------------------------------
 
@@ -1016,34 +1015,9 @@
 .. plot:: source/tutorial/examples/6.2
    :include-source:
    :doctest-format:
-
-
-.. figure:: interp_cubic.epsi
    :align: center
 
-   **Figure 3**  .. image: interp_cubic_der.epsi
-   
-   
-   
-   
-   .. image: interp_cubic_int.epsi
-   
-   
-   .. image: interp_cubic_param.epsi
-   
-   
-   
-   Examples of using cubic-spline interpolation. 
-   
-   .. _`fig:spline-1d`:
 
-
-
-
-.. literalinclude:: examples/6.2
-
-
-
 Two-dimensionsal spline representation (interpolate.bisplrep)
 -------------------------------------------------------------
 
@@ -1082,29 +1056,18 @@
 Figure `4 <#fig-2d-interp>`__ ). This example uses the :obj:`mgrid` command in SciPy which is useful for defining a "mesh-grid "in many dimensions. (See also the :obj:`ogrid` command if the full-mesh is not needed). The number of output
 arguments and the number of dimensions of each argument is determined
 by the number of indexing objects passed in :obj:`mgrid`[]. 
-.. literalinclude:: examples/6.3
 
+.. _`fig:2d_interp`:
 
-
-
-
-
-.. figure:: 2d_func.epsi
+.. plot:: source/tutorial/examples/6.3
+   :doctest-format:
+   :include-source:
    :align: center
 
-   **Figure 4**  .. image: 2d_interp.epsi
-   
-   
-   
-   Example of two-dimensional spline interpolation. 
-   
-   .. _`fig:2d_interp`:
+.. XXX: **Figure 4**  
+.. XXX: Example of two-dimensional spline interpolation. 
 
 
-
-
-
-
 Signal Processing (signal)
 ==========================
 
@@ -1221,26 +1184,18 @@
 :obj:`signal.convolve2d` which convolves arbitrary two-dimensional
 filters and allows for choosing mirror-symmetric boundary conditions.
 
+.. _`fig:lena_edge_spline`:
 
-.. literalinclude:: examples/6.4
-
-
-
-
-.. figure:: lena_image.epsi
+.. plot:: source/tutorial/examples/6.4
+   :doctest-format:
+   :include-source:
    :align: center
 
-   **Figure 5**  .. image: lena_edge.epsi
-   
-   
-   
-   Example of using smoothing splines to filter images. 
-   
-   .. _`fig:lena_edge_spline`:
+..   **Figure 5**  
+..   .. image: figs/lena_edge.pdf
+..   Example of using smoothing splines to filter images. 
 
 
-
-
 Filtering
 ---------
 
@@ -1250,11 +1205,16 @@
 operations. There are two broad kinds of filtering operations: linear
 and non-linear. Linear filters can always be reduced to multiplication
 of the flattened Numpy array by an appropriate matrix resulting in
-another flattened Numpy array. Of course, this is not usually the
-best way to compute the filter as the matrices and vectors involved
-may be huge. For example filtering a :math:`512\times512` image with this method would require multiplication of a :math:`512^{2}x512^{2}` matrix with a :math:`512^{2}` vector. Just trying to store the :math:`512^{2}\times512^{2}` matrix using a standard Numpy array would require :math:`68,719,476,736` elements. At 4 bytes per element this would require :math:`256\textrm{GB}` of memory. In most applications most of the elements of this matrix
-are zero and a different method for computing the output of the filter
-is employed. 
+another flattened Numpy array. Of course, this is not usually the best
+way to compute the filter as the matrices and vectors involved may be
+huge. For example filtering a :math:`512\times512` image with this
+method would require multiplication of a :math:`512^{2}x512^{2}`
+matrix with a :math:`512^{2}` vector. Just trying to store the
+:math:`512^{2}\times512^{2}` matrix using a standard Numpy array would
+require :math:`68,719,476,736` elements. At 4 bytes per element this
+would require :math:`256\textrm{GB}` of memory. In most applications
+most of the elements of this matrix are zero and a different method
+for computing the output of the filter is employed.
 
 
 Convolution/Correlation
@@ -1628,10 +1588,9 @@
     \[ \mathbf{A^{-1}=\frac{1}{25}\left[\begin{array}{ccc} -37 & 9 & 22\\ 14 & 2 & -9\\ 4 & -3 & 1\end{array}\right]=\left[\begin{array}{ccc} -1.48 & 0.36 & 0.88\\ 0.56 & 0.08 & -0.36\\ 0.16 & -0.12 & 0.04\end{array}\right].}\]
 
 The following example demonstrates this computation in SciPy 
+
 .. literalinclude:: examples/10.2.1
 
-
-
 Solving linear system
 ^^^^^^^^^^^^^^^^^^^^^
 
@@ -1657,10 +1616,9 @@
 However, it is better to use the linalg.solve command which can be
 faster and more numerically stable. In this case it gives the same
 answer as shown in the following example: 
+
 .. literalinclude:: examples/10.2.2
 
-
-
 Finding Determinant
 ^^^^^^^^^^^^^^^^^^^
 
@@ -1689,11 +1647,8 @@
 
 In SciPy this is computed as shown in this example: 
 
-
 .. literalinclude:: examples/10.2.3
 
-
-
 Computing norms
 ^^^^^^^^^^^^^^^
 
@@ -1794,13 +1749,11 @@
 
 where :math:`x_{i}=0.1i` for :math:`i=1\ldots10` , :math:`c_{1}=5` , and :math:`c_{2}=4.` Noise is added to :math:`y_{i}` and the coefficients :math:`c_{1}` and :math:`c_{2}` are estimated using linear least squares. 
 
+.. plot:: source/tutorial/examples/10.2.5
+   :include-source:
+   :align: center
 
-XXX: Unknown inset Box Frameless
 
-XXX: Unknown inset Box Frameless
-
-
-
 Generalized inverse
 ^^^^^^^^^^^^^^^^^^^
 
@@ -1924,11 +1877,8 @@
 the original equation. The eigenvectors associated with these
 eigenvalues can then be found. 
 
-
 .. literalinclude:: examples/10.3.1
 
-
-
 Singular value decomposition
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
@@ -1944,21 +1894,11 @@
 is the singular-value decomposition of :math:`\mathbf{A}.` Every matrix has a singular value decomposition. Sometimes, the
 singular values are called the spectrum of :math:`\mathbf{A}.` The command :obj:`linalg.svd` will return :math:`\mathbf{U}` , :math:`\mathbf{V}^{H}` , and :math:`\sigma_{i}` as an array of the singular values. To obtain the matrix :math:`\mathbf{\Sigma}` use :obj:`linalg.diagsvd`. The following example illustrates the use of :obj:`linalg.svd` . 
 
-
 .. literalinclude:: examples/10.3.2
 
-
-
-
 .. [#] A hermition matrix :math:`\mathbf{D}` satisfies :math:`\mathbf{D}^{H}=\mathbf{D}.` 
-    
-    
 
-
-
 .. [#] A unitary matrix :math:`\mathbf{D}` satisfies :math:`\mathbf{D}^{H}\mathbf{D}=\mathbf{I}=\mathbf{D}\mathbf{D}^{H}` so that :math:`\mathbf{D}^{-1}=\mathbf{D}^{H}.` 
-    
-    
 
 
 LU decomposition
@@ -2052,11 +1992,8 @@
 
 The following example illustrates the schur decomposition: 
 
-
 .. literalinclude:: examples/10.3.6
 
-
-
 Matrix Functions
 ----------------
 
@@ -2180,10 +2117,8 @@
 algorithm. For example the following code computes the zeroth-order
 Bessel function applied to a matrix.
 
-
 .. literalinclude:: examples/10.4.4
 
-
 Statistics
 ==========
 



More information about the Scipy-svn mailing list