Ticket #7981: trac-7981-show_options.patch

File trac-7981-show_options.patch, 5.6 KB (added by Jason Grout, 13 years ago)
  • sage/plot/animate.py

    # HG changeset patch
    # User Jason Grout <jason-sage@creativetrax.com>
    # Date 1263859232 28800
    # Node ID 6550ca173ac180c86ea63a6a20d08aa93d9ae12e
    # Parent  a04676507f24e265f65fdeeb6c456321e1a0b406
    Show options should be consolidated in .save(), not .show().  This lets commands like animate work correctly with show options that are passed through by graphics commands.
    
    diff -r a04676507f24 -r 6550ca173ac1 sage/plot/animate.py
    a b  
    5454        Animation with 5 frames
    5555        sage: a.show()          # optional -- requires convert command
    5656        sage: a[:5].show()      # optional
    57    
     57        sage: animate([plot(sin(x + float(k), (0,2*pi),ymin=-5,ymax=5)) for k in srange(0,2*pi,0.3)]).show() # optional
     58       
    5859    The ``show`` function takes arguments to specify the
    5960    delay between frames (measured in hundredths of a second, default
    6061    value 20) and the number of iterations (default value 0, which
  • sage/plot/plot.py

    diff -r a04676507f24 -r 6550ca173ac1 sage/plot/plot.py
    a b  
    14191419        # This option should not be passed on to save().
    14201420        linkmode = kwds.pop('linkmode', False)
    14211421
    1422         options = {}
    1423         options.update(self.SHOW_OPTIONS)
    1424         options.update(self._extra_kwds)
    1425         options.update(kwds)
    1426 
    14271422        if DOCTEST_MODE:
    1428             options.pop('filename')
    1429             self.save(DOCTEST_MODE_FILE, **options)
     1423            kwds.pop('filename',None)
     1424            self.save(filename=DOCTEST_MODE_FILE, **kwds)
    14301425        elif EMBEDDED_MODE:
    1431             if options['filename'] is None:
    1432                 options['filename'] = sage.misc.misc.graphics_filename()
    1433             self.save(**options)
     1426            kwds.setdefault('filename',sage.misc.misc.graphics_filename())
     1427            self.save(**kwds)
    14341428            if linkmode == True:
    1435                 return "<img src='cell://%s'>" % options['filename']
     1429                return "<img src='cell://%s'>" % kwds['filename']
    14361430            else:
    1437                 html("<img src='cell://%s'>" % options['filename'])
     1431                html("<img src='cell://%s'>" % kwds['filename'])
    14381432        else:
    1439             if options['filename'] is None:
    1440                 options['filename'] = sage.misc.misc.tmp_filename() + '.png'
    1441             self.save(**options)
     1433            kwds.setdefault('filename',sage.misc.misc.tmp_filename() + '.png')
     1434            self.save(**kwds)
    14421435            os.system('%s %s 2>/dev/null 1>/dev/null &' % \
    1443                 (sage.misc.viewer.browser(), options['filename']))
     1436                (sage.misc.viewer.browser(), kwds['filename']))
    14441437
    14451438    def xmin(self, xmin=None):
    14461439        """
     
    18951888        #subplot.autoscale_view(tight=True)
    18961889        return figure
    18971890
    1898     def save(self, filename=None, dpi=DEFAULT_DPI, savenow=True, *args, **kwds):
     1891    def save(self, filename=None, savenow=True, *args, **kwds):
    18991892        r"""
    19001893        Save the graphics to an image file of type: PNG, PS, EPS, SVG,
    19011894        SOBJ, depending on the file extension you give the filename.
     
    19211914
    19221915        ::
    19231916
    1924             sage: c.show(figsize=[5,5], xmin=-1, xmax=3, ymin=-1, ymax=3)       
     1917            sage: c.show(figsize=[5,5], xmin=-1, xmax=3, ymin=-1, ymax=3)                   sage: point((-1,1),pointsize=30, color='red')
    19251918
     1919        Also, show options are correctly passed from the graphics object::
    19261920
    1927        
    1928         ::
    1929        
    1930             sage: point((-1,1),pointsize=30, color='red')
     1921            sage: c=circle((1,1), 1, color='red',xmin=-3,xmax=3,ymin=-4,ymax=5)
     1922            sage: c.save(DOCTEST_MODE_FILE)
    19311923
    19321924        By default, the figure grows to include all of the graphics
    19331925        and text, so the final image may not be exactly the figure
     
    19451937            return
    19461938
    19471939        if savenow:
    1948             options=dict()
    1949             options['transparent']=kwds.pop('transparent',False)
    1950             figure=self.matplotlib(*args, **kwds)
     1940            show_options=dict()
     1941            show_options.update(self.SHOW_OPTIONS)
     1942            show_options.update(self._extra_kwds)
     1943            show_options.update(kwds)
     1944
     1945            save_options=dict()
     1946            save_options['transparent']=show_options.pop('transparent',False)
     1947            save_options['dpi']=show_options.pop('dpi',DEFAULT_DPI)
     1948
     1949            figure=self.matplotlib(*args, **show_options)
    19511950            # You can output in PNG, PS, EPS, PDF, or SVG format, depending on the file extension.
    19521951            # matplotlib looks at the file extension to see what the renderer should be.
    19531952            # The default is FigureCanvasAgg for PNG's because this is by far the most
     
    19561955            from matplotlib.backends.backend_agg import FigureCanvasAgg
    19571956            figure.set_canvas(FigureCanvasAgg(figure))
    19581957
    1959             if ext in ['.eps', '.ps', '.pdf']:
    1960                 if dpi is None:
    1961                     dpi = 72
    1962             elif ext == '.svg':
    1963                 if dpi is None:
    1964                     dpi = 80
    1965             elif ext == '.png':
    1966                 if dpi is None:
    1967                     dpi = 100
    1968             else:
    1969                 raise ValueError, "file extension must be either 'png', 'ps, 'eps', 'pdf, 'svg' or 'sobj'"
    1970             figure.savefig(filename,dpi=dpi,bbox_inches='tight',**options)
     1958            if ext not in ['.svg', '.png', '.eps', '.ps', '.pdf']:
     1959                raise ValueError, "file extension must be either 'png', 'ps, 'eps', 'pdf, 'svg', or 'sobj'"
     1960            figure.savefig(filename,bbox_inches='tight',**save_options)
    19711961
    19721962
    19731963_SelectiveFormatterClass = None