Changeset 5278:122c820a2276


Ignore:
Timestamp:
07/04/07 16:56:19 (6 years ago)
Author:
William Stein <wstein@…>
Branch:
default
Message:

Added/improved how animated plotting works in SAGE.

Location:
sage/plot
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • sage/plot/all.py

    r5263 r5278  
    55                  plot_vector_field, matrix_plot, bar_chart, 
    66                  is_Graphics, 
    7                   show_default, 
    8                   plot_animated_gif) 
     7                  show_default) 
     8 
     9from animate import Animation as animate 
    910 
    1011from plot3d import (Graphics3d, point3d, line3d, plot3d) 
  • sage/plot/plot.py

    r5265 r5278  
    120120""" 
    121121 
    122 #***************************************************************************** 
    123 #  Copyright (C) 2006 Alex Clemesha <clemesha@gmail.com> and William Stein <wstein@ucsd.edu> 
    124 # 
     122############################################################################ 
     123#  Copyright (C) 2006 Alex Clemesha <clemesha@gmail.com> and William Stein <wstein@gmail.com> 
    125124#  Distributed under the terms of the GNU General Public License (GPL) 
    126 # 
    127125#                  http://www.gnu.org/licenses/ 
    128 #***************************************************************************** 
    129  
    130 import pdb 
     126############################################################################ 
    131127 
    132128from sage.structure.sage_object import SageObject 
    133129 
    134 ## IMPORTANT: Do not import matplotlib at module scope.  It takes a 
     130## IMPORTANT: Do *not* import matplotlib at module scope.  It takes a 
    135131## surprisingliy long time to initialize itself.  It's better if it is 
    136132## imported in functions, so it only gets started if it is actually 
     
    26842680        if not isinstance(array, (list, tuple)): 
    26852681            raise TypeError,"array (=%s) must be a list of lists of Graphics objects"%(array) 
     2682        array = list(array) 
    26862683        self._glist = [] 
    26872684        self._rows = len(array) 
     
    29132910    return R 
    29142911 
    2915  
    2916  
    2917 ##################################### 
    2918 def plot_animated_gif(G, delay=20, outfile=None, iterations=0, 
    2919                       xmin=None, xmax=None, ymin=None, ymax=None, *args, **kwds): 
    2920     """ 
    2921     Returns an animated gif composed from rendering the 
    2922     graphics objects in the list G. 
    2923  
    2924     This function will only work if the Imagemagick command line tools 
    2925     package is installed, i.e., you have the"convert" command. 
    2926  
    2927     INPUT: 
    2928         G -- a list of plot objects 
    2929         delay -- (default: 20) delay in hundredths of a second between frames 
    2930         outfile -- file that the animated gif gets saved to 
    2931         iterations -- integer (default: 0); number of iterations of 
    2932                       animation.  If 0, loop forever.  
    2933         other options -- all are passed to the save command,  
    2934                          which is called on each input. 
    2935  
    2936     AUTHOR: 
    2937         -- William Stein 
    2938     """ 
    2939     if not outfile: 
    2940         outfile = sage.misc.misc.graphics_filename(ext='gif') 
    2941     if len(G) == 0: 
    2942         raise ValueError, "G must be nonempty" 
    2943     d = sage.misc.misc.tmp_dir() 
    2944     if xmin is None: xmin = G[0].xmin() 
    2945     if xmax is None: xmax = G[0].xmax() 
    2946     if ymin is None: ymin = G[0].ymin() 
    2947     if ymax is None: ymax = G[0].ymax() 
    2948     for i in range(len(G)): 
    2949         filename = '%s/%s'%(d,sage.misc.misc.pad_zeros(i,8)) 
    2950         G[i].save(filename + '.png', xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, *args, **kwds) 
    2951     if not outfile.endswith('.gif'): 
    2952         outfile += '.gif' 
    2953     outfile = os.path.abspath(outfile) 
    2954     cmd = 'cd "%s"; convert -delay %s -loop %s *.png "%s"'%(d, int(delay), int(iterations), outfile) 
    2955     os.system(cmd) 
    2956  
Note: See TracChangeset for help on using the changeset viewer.