[matplotlib-devel] print_figure(), savefig() and file-like objects

2006-07-20 Thread Steven Chaplin
I just updated backend_cairo.py to work with the latest version of pycairo.
The cairo backend can now output PNG, PDF, PS and SVG to a filename or a
file-like object.

However, print_figure() does not support writing to file objects in
different formats because it only takes a 'filename' argument and does not
have an argument to allow you to specify the format.
If the filename is string-like it writes to the filename (and the format is
often encoded into the string, as in 'file.png' for example)
If the filename is not string-like the backend has no way to know which
format is required and has to choose a default format (agg defaults to PNG).

I think print_figure() should be changed from
print_figure (filename, ...)
to
print_figure (filename, format='png', ...)
where format is in ('png', 'ps', 'svg') etc
And savefig() would need a corresponding change.

This would allow backends to write to file-like objects in the requested
format. For example, you could then write to a file-like object in SVG format.

Any comments?

Regards,
Steve

Send instant messages to your online friends http://au.messenger.yahoo.com 


-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] print_figure(), savefig() and file-like objects

2006-07-21 Thread Steven Chaplin
On Fri, 2006-07-21 at 17:21 -0500, Ken McIvor wrote:
> On Jul 20, 2006, at 7:53 AM, Steven Chaplin wrote:
> >
> > However, print_figure() does not support writing to file objects in
> > different formats because it only takes a 'filename' argument and  
> > does not
> > have an argument to allow you to specify the format.
> 
> You can usually get the filename from the "name" attribute of a file- 
> like object.  Below is some untested pseudo-Python code that will use  
> the value of "format" if it's specified and will otherwise try to  
> pull the format from the file name.  You should be able to collapse  
> the nested if/else structure -- I've covered all four permutations  
> explicitly for clarity.
> 
> I'm too swamped to put a lot of time into this code/explanation, so  
> please let me know if this doesn't make any sense.
> 
> Ken
> 
> 
> def print_figure(self, fileOrString, format=None):
>   extension = None
> 
>   if is_file_like(fileOrString):
>   filename = getattr(fileobj, 'name', None)
>   else:
>   filename = fileOrString
> 
>   if filename is not None:
>   # get the extension and make it all lower-case
>   extension = os.path.splitext(filename, None)
> 
>   # figure out what the format is
>   if extension is None:
>   # no name file, so use format
>   if format is None:
>   raise ValueError('you must specify a format')
>   else:
>   pass # use the value of "format"
> else:
>   # there's a name, but the format keyword overrides it
>   if format is None:
>   # use the file extension
>   format = extension
>   else:
>   pass # use the value of "format"
> 
>   format = format.lower()
>   if format not in ('png', 'ps', 'svg'):
>   raise ValueError('invalid file format %r' % (format,))
> 
>   # At this point in the method, "format" is the requested file format.

The 'name' attribute is only useful sometimes:
 - it works for file objects (but only when the filename ends with a
format extension)
 - it does not work for sys.stdout, StringIO or cStringIO file-like
objects
I think an explicit 'format' argument is better than reading a 'name'
attribute which only works sometimes.

Steve

Send instant messages to your online friends http://au.messenger.yahoo.com 


-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


[matplotlib-devel] numpy

2006-09-25 Thread Steven Chaplin
When using the latest matplotlib from svn and numpy version 0.9.6 I get:

$ ./simple_plot.py
Traceback (most recent call last):
  File "./simple_plot.py", line 6, in ?
from pylab import *
  File "/usr/lib/python2.4/site-packages/pylab.py", line 1, in ?
from matplotlib.pylab import *
  File "/usr/lib/python2.4/site-packages/matplotlib/pylab.py", line 197, in ?
import cm
  File "/usr/lib/python2.4/site-packages/matplotlib/cm.py", line 5, in ?
import colors
  File "/usr/lib/python2.4/site-packages/matplotlib/colors.py", line 33, in ?
from numerix import array, arange, take, put, Float, Int, where, \
  File "/usr/lib/python2.4/site-packages/matplotlib/numerix/__init__.py", line 
145, in ?
__import__('fft', g, l)
  File "/usr/lib/python2.4/site-packages/matplotlib/numerix/fft/__init__.py", 
line 11, in ?
from numpy.dft.old import *
ImportError: No module named old

Does mpl only work with specific versions of numpy?
Should mpl check for a required version and report an error if its not there?

Steve

Send instant messages to your online friends http://au.messenger.yahoo.com 


-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel