On Wed, 17 Nov 2010 at 06:21PM -0800, kcrisman wrote: > I'd like to point out that > http://trac.sagemath.org/sage_trac/ticket/5128 might also be relevant > - Dan D., can you comment on whether an eventual solution to that > ticket would take care of this? (I assume, out of ignorance, that > there isn't anything else obvious one can do to the current SageTeX > package or Sage to do this directly.)
You're correct that there's nothing *obvious* one can do. But I think
there's something non-obvious...
When you do \sageplot{p} in SageTeX, it doesn't require much of the
object `p'. It basically needs to be able to do
p.save('path/foo.png')
and get a PNG file saved properly. It's very useful for 'foo.eps' and
'foo.pdf' to also work.
So, you don't really need a Sage Graphics() object; you just need
something that has an appropriate save() method. So it's possible that
something like this would work:
class GoodEnoughGraphics():
def __init__(self, obj):
self.obj = obj
def save(filename):
if filename.endswith('png'):
# do whatever you need to do to save a PNG to `filename'
if filename.endswith('eps'):
# do whatever you need to do to save an EPS to `filename'
# etc
So, if you're working with pure matplotlib graphics, you would write the
above class putting whatever specific code you need in .save(), and then
do something like \sageplot{GoodEnoughGraphics(p)}. This approach should
work for any kind of graphics whatsoever; if you can somehow save them
to the right kind of file, then you can write the above wrapper.
I see that the OP effectively did this; see above where he did "plt.save
= plt.savefig", which gives his object the .save() method that SageTeX
wants.
As a disclaimer: I haven't tested any of this, or even looked at the
SageTeX code to make sure it would work. So caveat emptor. :) Let me
know if this works!
Dan
--
--- Dan Drake
----- http://mathsci.kaist.ac.kr/~drake
-------
signature.asc
Description: Digital signature
