From: <jd...@us...> - 2008-10-17 15:35:15
|
Revision: 6241 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6241&view=rev Author: jdh2358 Date: 2008-10-17 15:35:05 +0000 (Fri, 17 Oct 2008) Log Message: ----------- added joshuas movie demo Modified Paths: -------------- trunk/matplotlib/doc/faq/howto_faq.rst trunk/matplotlib/doc/faq/installing_faq.rst Added Paths: ----------- trunk/matplotlib/examples/animation/animation_blit_gtk.py trunk/matplotlib/examples/animation/movie_demo.py Removed Paths: ------------- trunk/matplotlib/examples/animation/animation_blit.py Modified: trunk/matplotlib/doc/faq/howto_faq.rst =================================================================== --- trunk/matplotlib/doc/faq/howto_faq.rst 2008-10-17 14:31:38 UTC (rev 6240) +++ trunk/matplotlib/doc/faq/howto_faq.rst 2008-10-17 15:35:05 UTC (rev 6241) @@ -299,7 +299,7 @@ for a single point use :func:`~matplotlib.nxutils.pnpoly` and for an array of points use :func:`~matplotlib.nxutils.points_inside_poly`. For a discussion of the implementation see `pnpoly -<http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html>`_. +<http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html>`_. .. sourcecode:: ipython @@ -334,5 +334,140 @@ Out[32]: array([False, False, False, False, False, False, False, True, False, True], dtype=bool) .. htmlonly:: - + For a complete example, see :ref:`event_handling-lasso_demo`. + + +.. _how-to-submit-patch: + +How do I submit a patch? +======================== + +First obtain a copy of matplotlib svn (see :ref:`install-svn`) and +make your changes to the matplotlib source code or documentation and +apply a `svn diff`. If it is feasible, do your diff from the top +level directory, the one that contains :file:`setup.py`. Eg,:: + + > cd /path/to/matplotlib/source + > svn diff > mypatch.diff + +and then post your patch to the `matplotlib-devel +<http://sourceforge.net/mail/?group_id=80706>`_ mailing list. If you +do not get a response within 24 hours, post your patch to the +sourceforge patch `tracker +<http://sourceforge.net/tracker2/?atid=560722&group_id=80706&func=browse>`_, +and follow up on the mailing list with a link to the sourceforge patch +submissions. If you still do not hear anything within a week (this +shouldn't happen!), send us a kind and gentle reminder on the mailing +list. + +If you have made lots of local changes and do not want to a diff +against the entire tree, but rather against a single directory or +file, that is fine, but we do prefer svn diffs against HEAD. + +You should check out the guide to developing matplotlib to make sure +your patch abides by our coding conventions +:ref:`developers-guide-index`. + + +.. _howto-click-maps: + +Clickable images for HTML +========================= + +Andrew Dalke of `Dalke Scientific <http://www.dalkescientific.com>`_ +has written a nice `article +<http://www.dalkescientific.com/writings/diary/archive/2005/04/24/interactive_html.html>`_ +on how to make html click maps with matplotlib agg PNGs. We would +also like to add this functionality to SVG and add a SWF backend to +support these kind of images. If you are interested in contributing +to these efforts that would be great. + +.. _howto-set-zorder: + +How do I control the depth of plot elements? +============================================= + +Within an axes, the order that the various lines, markers, text, +collections, etc appear is determined by the +:meth:`matplotlib.artist.Artist.set_zorder` property. The default +order is patches, lines, text, with collections of lines and +collections of patches appearing at the same level as regular lines +and patches, respectively:: + + line, = ax.plot(x, y, zorder=10) + + + +.. htmlonly:: + + See :ref:`pylab_examples-zorder_demo` for a complete example. + +You can also use the Axes property +:meth:`matplotlib.axes.Axes.set_axisbelow` to control whether the grid +lines are placed above or below your other plot elements. + +.. _howto-axis-equal: + +How to I make the aspect ratio for plots equal? +=============================================== + +The Axes property :meth:`matplotlib.axes.Axes.set_aspect` controls the +aspect ratio of the axes. You can set it to be 'auto', 'equal', or +some ratio which controls the ratio:: + + ax = fig.add_subplot(111, aspect='equal') + + + +.. htmlonly:: + + See :ref:`pylab_examples-equal_aspect_ratio` for a complete example. + + +.. _howto-movie: + +How do I make a movie? +====================== + + +If you want to take an animated plot and turn it into a movie, the +best approach is to save a series of image files (eg PNG) and use an +external tool to convert them to a movie. You can use ` mencoder +<http://www.mplayerhq.hu/DOCS/HTML/en/mencoder.html>`_, +which is part of the `mplayer <http://www.mplayerhq.hu>`_ suite +for this:: + + + #fps (frames per second) controls the play speed + mencoder 'mf://*.png' -mf type=png:fps=10 -ovc \\ + lavc -lavcopts vcodec=wmv2 -oac copy -o animation.avi + +The swiss army knife of image tools, ImageMagick's `convert +<http://www.imagemagick.org/script/convert.php>`_ works for this as +well.<p> + +Here is a simple example script that saves some PNGs, makes them into +a movie, and then cleans up:: + + import os, sys + import matplotlib.pyplot as plt + + files = [] + fig = plt.figure(figsize=(5,5)) + ax = fig.add_subplot(111) + for i in range(50): # 50 frames + ax.cla() + ax.imshow(rand(5,5), interpolation='nearest') + fname = '_tmp%03d.png'%i + print 'Saving frame', fname + fig.savefig(fname) + files.append(fname) + + print 'Making movie animation.mpg - this make take a while' + os.system("mencoder 'mf://_tmp*.png' -mf type=png:fps=10 \\ + -ovc lavc -lavcopts vcodec=wmv2 -oac copy -o animation.mpg") + +.. htmlonly:: + + See :ref:`animation-movie_demo` for a complete example. Modified: trunk/matplotlib/doc/faq/installing_faq.rst =================================================================== --- trunk/matplotlib/doc/faq/installing_faq.rst 2008-10-17 14:31:38 UTC (rev 6240) +++ trunk/matplotlib/doc/faq/installing_faq.rst 2008-10-17 15:35:05 UTC (rev 6241) @@ -105,6 +105,8 @@ > cd matplotlib > python setup.py install + + Backends ======== Deleted: trunk/matplotlib/examples/animation/animation_blit.py =================================================================== --- trunk/matplotlib/examples/animation/animation_blit.py 2008-10-17 14:31:38 UTC (rev 6240) +++ trunk/matplotlib/examples/animation/animation_blit.py 2008-10-17 15:35:05 UTC (rev 6241) @@ -1,57 +0,0 @@ -#!/usr/bin/env python - -# For detailed comments on animation and the techniques used here, see -# the wiki entry -# http://www.scipy.org/wikis/topical_software/MatplotlibAnimation -import sys -import time - -import gtk, gobject - -import matplotlib -matplotlib.use('GTKAgg') -import numpy as npy -import pylab as p - - -ax = p.subplot(111) -canvas = ax.figure.canvas - -p.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs -p.grid() # to ensure proper background restore - -# create the initial line -x = npy.arange(0,2*npy.pi,0.01) -line, = p.plot(x, npy.sin(x), animated=True, lw=2) - -# for profiling -tstart = time.time() - -def update_line(*args): - if update_line.background is None: - update_line.background = canvas.copy_from_bbox(ax.bbox) - - # restore the clean slate background - canvas.restore_region(update_line.background) - # update the data - line.set_ydata(npy.sin(x+update_line.cnt/10.0)) - # just draw the animated artist - try: - ax.draw_artist(line) - except AssertionError: - return - # just redraw the axes rectangle - canvas.blit(ax.bbox) - - if update_line.cnt==1000: - # print the timing info and quit - print 'FPS:' , 1000/(time.time()-tstart) - sys.exit() - - update_line.cnt += 1 - return True - -update_line.cnt = 0 -update_line.background = None -gobject.idle_add(update_line) -p.show() Copied: trunk/matplotlib/examples/animation/animation_blit_gtk.py (from rev 6240, trunk/matplotlib/examples/animation/animation_blit.py) =================================================================== --- trunk/matplotlib/examples/animation/animation_blit_gtk.py (rev 0) +++ trunk/matplotlib/examples/animation/animation_blit_gtk.py 2008-10-17 15:35:05 UTC (rev 6241) @@ -0,0 +1,68 @@ +#!/usr/bin/env python + +# For detailed comments on animation and the techniques used here, see +# the wiki entry +# http://www.scipy.org/wikis/topical_software/MatplotlibAnimation +import time + +import gtk, gobject + +import matplotlib +matplotlib.use('GTKAgg') + +import numpy as np +import matplotlib.pyplot as plt + + +fig = plt.figure() +ax = fig.add_subplot(111) +canvas = fig.canvas + +fig.subplots_adjust(left=0.3, bottom=0.3) # check for flipy bugs +ax.grid() # to ensure proper background restore + +# create the initial line +x = np.arange(0,2*np.pi,0.01) +line, = ax.plot(x, np.sin(x), animated=True, lw=2) +canvas.draw() + +# for profiling +tstart = time.time() + +def update_line(*args): + print 'you are here', update_line.cnt + if update_line.background is None: + update_line.background = canvas.copy_from_bbox(ax.bbox) + + # restore the clean slate background + canvas.restore_region(update_line.background) + # update the data + line.set_ydata(np.sin(x+update_line.cnt/10.0)) + # just draw the animated artist + ax.draw_artist(line) + + # just redraw the axes rectangle + canvas.blit(ax.bbox) + + if update_line.cnt==1000: + # print the timing info and quit + print 'FPS:' , 1000/(time.time()-tstart) + gtk.mainquit() + raise SystemExit + + update_line.cnt += 1 + return True + +update_line.cnt = 0 +update_line.background = None + + +def start_anim(event): + gobject.idle_add(update_line) + canvas.mpl_disconnect(start_anim.cid) + +start_anim.cid = canvas.mpl_connect('draw_event', start_anim) + + + +plt.show() Added: trunk/matplotlib/examples/animation/movie_demo.py =================================================================== --- trunk/matplotlib/examples/animation/movie_demo.py (rev 0) +++ trunk/matplotlib/examples/animation/movie_demo.py 2008-10-17 15:35:05 UTC (rev 6241) @@ -0,0 +1,140 @@ +#!/usr/bin/python +# +# Josh Lifton 2004 +# +# Permission is hereby granted to use and abuse this document +# so long as proper attribution is given. +# +# This Python script demonstrates how to use the numarray package +# to generate and handle large arrays of data and how to use the +# matplotlib package to generate plots from the data and then save +# those plots as images. These images are then stitched together +# by Mencoder to create a movie of the plotted data. This script +# is for demonstration purposes only and is not intended to be +# for general use. In particular, you will likely need to modify +# the script to suit your own needs. +# + + +from matplotlib.matlab import * # For plotting graphs. +import os # For issuing commands to the OS. +import sys # For determining the Python version. + +# +# Print the version information for the machine, OS, +# Python interpreter, and matplotlib. The version of +# Mencoder is printed when it is called. +# +# This script is known to have worked for: +# +# OS version: ('Linux', 'flux-capacitor', '2.4.26', '#1 SMP Sa Apr 17 19:33:42 CEST 2004', 'i686') +# Python version: 2.3.4 (#2, May 29 2004, 03:31:27) [GCC 3.3.3 (Debian 20040417)] +# matplotlib version: 0.61.0 +# MEncoder version: +# MEncoder 1.0pre4-3.3.3 (C) 2000-2004 MPlayer Team +# CPU: Intel Celeron 2/Pentium III Coppermine,Geyserville 996.1 MHz (Family: 6, Stepping: 10) +# Detected cache-line size is 32 bytes +# CPUflags: Type: 6 MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 0 +# Compiled for x86 CPU with extensions: MMX MMX2 SSE +# +print 'Executing on', os.uname() +print 'Python version', sys.version +print 'matplotlib version', matplotlib.__version__ + + + +# +# First, let's create some data to work with. In this example +# we'll use a normalized Gaussian waveform whose mean and +# standard deviation both increase linearly with time. Such a +# waveform can be thought of as a propagating system that loses +# coherence over time, as might happen to the probability +# distribution of a clock subjected to independent, identically +# distributed Gaussian noise at each time step. +# + +print 'Initializing data set...' # Let the user know what's happening. + +# Initialize variables needed to create and store the example data set. +numberOfTimeSteps = 100 # Number of frames we want in the movie. +x = arange(-10,10,0.01) # Values to be plotted on the x-axis. +mean = -6 # Initial mean of the Gaussian. +stddev = 0.2 # Initial standard deviation. +meaninc = 0.1 # Mean increment. +stddevinc = 0.1 # Standard deviation increment. + +# Create an array of zeros and fill it with the example data. +y = zeros((numberOfTimeSteps,len(x)), Float64) +for i in range(numberOfTimeSteps) : + y[i] = (1/sqrt(2*pi*stddev))*exp(-((x-mean)**2)/(2*stddev)) + mean = mean + meaninc + stddev = stddev + stddevinc + +print 'Done.' # Let the user know what's happening. + +# +# Now that we have an example data set (x,y) to work with, we can +# start graphing it and saving the images. +# + +for i in range(len(y)) : + # + # The next four lines are just like Matlab. + # + plot(x,y[i],'b.') + axis((x[0],x[-1],-0.25,1)) + xlabel('time (ms)') + ylabel('probability density function') + + # + # Notice the use of LaTeX-like markup. + # + title(r'$\cal{N}(\mu, \sigma^2)$', fontsize=20) + + # + # The file name indicates how the image will be saved and the + # order it will appear in the movie. If you actually wanted each + # graph to be displayed on the screen, you would include commands + # such as show() and draw() here. See the matplotlib + # documentation for details. In this case, we are saving the + # images directly to a file without displaying them. + # + filename = str('%03d' % i) + '.png' + savefig(filename, dpi=100) + + # + # Let the user know what's happening. + # + print 'Wrote file', filename + + # + # Clear the figure to make way for the next image. + # + clf() + +# +# Now that we have graphed images of the dataset, we will stitch them +# together using Mencoder to create a movie. Each image will become +# a single frame in the movie. +# +# We want to use Python to make what would normally be a command line +# call to Mencoder. Specifically, the command line call we want to +# emulate is (without the initial '#'): +# mencoder mf://*.png -mf type=png:w=800:h=600:fps=25 -ovc lavc -lavcopts vcodec=mpeg4 -oac copy -o output.avi +# See the MPlayer and Mencoder documentation for details. +# + +command = ('mencoder', + 'mf://*.png', + '-mf', + 'type=png:w=800:h=600:fps=25', + '-ovc', + 'lavc', + '-lavcopts', + 'vcodec=mpeg4', + '-oac', + 'copy', + '-o', + 'output.avi') + +os.spawnvp(os.P_WAIT, 'mencoder', command) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |