emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] python/babel inline images


From: Mikhail Titov
Subject: Re: [O] python/babel inline images
Date: Thu, 7 Jun 2012 10:09:58 -0500

> -----Original Message-----
> From: henry atting [mailto:address@hidden
> Sent: Thursday, June 07, 2012 3:43 AM
> To: Mikhail Titov
> Cc: 'henry atting'; address@hidden
> Subject: Re: python/babel inline images
> 
> >> The code itself works flawlessly. So
> >> the workaround which I already have used is to link to the resulting
> >> image. The only drawback with this solution is that after every
> >> evaluation I have to remove the empty `'Results:'
> >
> > You can use :results silent
> 
> This is great! Actually this solves my problem which means: create a link
> to the file and set results to silent.

This has an implication of inability to cache results in case you might want
it. I personally would just leave empty #+RESULTS: block as is and I would
place link manually two lines below it (leave 1 blank line so re-evaluation
won't delete your link).

> 
> >> but the heck with
> >> it, I can live with it happily till the end of my days.
> >> However I find that some inconsistency lies therein. Before
> >> python/matplotlib I used gnuplot with which babel had no problem of
> >> this type.
> >
> > Try using
> >
> > ... :file exp_csv.svg
> > ...
> > plot.savefig(file=sys.stdout)
> 
> This does not compile, the compiler complains about missing arguments.
> I have to write it like this:
> 
> plot.savefig("file.svg", format='svg')

I never used that library but it makes sense:-) The only problem with this
solution that you should make sure nothing else goes to stdout. I think it
is a huge shortcoming.

> So, just to mention the current state of affairs (with a simple
> example):
> 
> --8<---------------cut here---------------start------------->8---
> #+begin_src python   :results output
> from pylab import *
> 
> t = arange(0.0, 2.0, 0.01)
> s = sin(2*pi*t)
> plot(t, s)
> show()
> savefig("file.svg", format='svg')
> #+end_src
> --8<---------------cut here---------------start------------->8---
> 
> The above code works. But if I set `:file' to `file.svg' with every
> evaluation the link to the file is placed after #+RESULTS: but the
> file itself is empty.

As William LECHELLE pointed out that in this case file captures the output
of the savefig() call which does not output anything to stdout. So it is
expected.

> If the code is evaluated without `:file
> file.svg' the evaluation simply works and the file.svg appears in the
> working directory.

I think this is the best way to proceed.

M.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]