# 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
|
|
54 | 54 | Animation with 5 frames |
55 | 55 | sage: a.show() # optional -- requires convert command |
56 | 56 | 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 | |
58 | 59 | The ``show`` function takes arguments to specify the |
59 | 60 | delay between frames (measured in hundredths of a second, default |
60 | 61 | value 20) and the number of iterations (default value 0, which |
diff -r a04676507f24 -r 6550ca173ac1 sage/plot/plot.py
a
|
b
|
|
1419 | 1419 | # This option should not be passed on to save(). |
1420 | 1420 | linkmode = kwds.pop('linkmode', False) |
1421 | 1421 | |
1422 | | options = {} |
1423 | | options.update(self.SHOW_OPTIONS) |
1424 | | options.update(self._extra_kwds) |
1425 | | options.update(kwds) |
1426 | | |
1427 | 1422 | 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) |
1430 | 1425 | 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) |
1434 | 1428 | if linkmode == True: |
1435 | | return "<img src='cell://%s'>" % options['filename'] |
| 1429 | return "<img src='cell://%s'>" % kwds['filename'] |
1436 | 1430 | else: |
1437 | | html("<img src='cell://%s'>" % options['filename']) |
| 1431 | html("<img src='cell://%s'>" % kwds['filename']) |
1438 | 1432 | 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) |
1442 | 1435 | os.system('%s %s 2>/dev/null 1>/dev/null &' % \ |
1443 | | (sage.misc.viewer.browser(), options['filename'])) |
| 1436 | (sage.misc.viewer.browser(), kwds['filename'])) |
1444 | 1437 | |
1445 | 1438 | def xmin(self, xmin=None): |
1446 | 1439 | """ |
… |
… |
|
1895 | 1888 | #subplot.autoscale_view(tight=True) |
1896 | 1889 | return figure |
1897 | 1890 | |
1898 | | def save(self, filename=None, dpi=DEFAULT_DPI, savenow=True, *args, **kwds): |
| 1891 | def save(self, filename=None, savenow=True, *args, **kwds): |
1899 | 1892 | r""" |
1900 | 1893 | Save the graphics to an image file of type: PNG, PS, EPS, SVG, |
1901 | 1894 | SOBJ, depending on the file extension you give the filename. |
… |
… |
|
1921 | 1914 | |
1922 | 1915 | :: |
1923 | 1916 | |
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') |
1925 | 1918 | |
| 1919 | Also, show options are correctly passed from the graphics object:: |
1926 | 1920 | |
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) |
1931 | 1923 | |
1932 | 1924 | By default, the figure grows to include all of the graphics |
1933 | 1925 | and text, so the final image may not be exactly the figure |
… |
… |
|
1945 | 1937 | return |
1946 | 1938 | |
1947 | 1939 | 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) |
1951 | 1950 | # You can output in PNG, PS, EPS, PDF, or SVG format, depending on the file extension. |
1952 | 1951 | # matplotlib looks at the file extension to see what the renderer should be. |
1953 | 1952 | # The default is FigureCanvasAgg for PNG's because this is by far the most |
… |
… |
|
1956 | 1955 | from matplotlib.backends.backend_agg import FigureCanvasAgg |
1957 | 1956 | figure.set_canvas(FigureCanvasAgg(figure)) |
1958 | 1957 | |
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) |
1971 | 1961 | |
1972 | 1962 | |
1973 | 1963 | _SelectiveFormatterClass = None |