3

If I use this block

#+BEGIN_SRC python :results file
from pylab import *
plot(rand(10))
savefig('images/test.png')
return 'images/test.png'
#+END_SRC 

then the RESULTS block shows me an inlined version of the plot.

If now I switch to this block

#+BEGIN_SRC python :session test :results file
from pylab import *
plot(rand(10))
savefig('images/test.png')
return 'images/test.png'
#+END_SRC 

then the RESULTS block does not show the inlined plot but this

| <matplotlib.lines.Line2D | object | at | 0x35c0650> |

Using a session is kind of mandatory for me because I need several blocks to share variables.

Is there something evidently wrong with my approach?

0

1 Answer 1

2

As per the org-mode documentation, you have to drop the return if the code is running in a session.

#+BEGIN_SRC python :session test :results file
  from pylab import *
  plot(rand(10))
  savefig('images/test.png')
  'images/test.png'
#+END_SRC 

#+RESULTS:
[[file:images/test.png]]

because "the result returned is the result of the last evaluation performed by the interpreter."

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.