Hi,

I often use matplotlib directly (for various reasons) in sage. 
Unfortunately, a common error that crops up is matplotlib's pdf backend has 
difficulty with Sage's wrapped integer and float representations.

i.e. 
sage: import pylab as pl
pl.plot([1,2,3]sage: pl.plot([1,2,3], linewidth=3.5)
[<matplotlib.lines.Line2D object at 0x10d57aed0>]
sage: pl.savefig
pl.savefig
sage: pl.savefig('/tmp/foo.pdf')
will generate an exception:
/Applications/Sage-4.6.2-OSX-64bit-10.6.app/Contents/Resources/sage/local/lib/python2.6/site-packages/matplotlib/backends/backend_pdf.pyc
 
in pdfRepr(obj)
    207         raise TypeError, \
    208             "Don't know a PDF representation for %s objects." \
--> 209             % type(obj)
    210 
    211 class Reference(object):

TypeError: Don't know a PDF representation for <type 
'sage.rings.real_mpfr.RealLiteral'> objects.
[and likewise for sage integers].

This error can be fixed by wrapping all the literals in int() and float() 
conversions which is cumbersome. I would like to make a cleaner fix but I 
was after some advice about the best way to go about this. One option is to 
add an extra test in backend_pdf.py in matplotlib to test float-like and 
int-like objects. An alternative would be to add extra pdfRepr methods to 
the Sage classes which can provide a pdf representation of class.

I'm not sure which is the more advisable approach likely to be welcomed as a 
patch. Advice requested.

Jonny

-- 
To post to this group, send an email to [email protected]
To unsubscribe from this group, send an email to 
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to