In the following link you can find the following simple example:
#+begin_src python :session :results file
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(3,2))
plt.plot([1,3,2])
fig.tight_layout()
plt.savefig('images/myfig.pdf')
'images/myfig.pdf' # return this to org-mode
#+end_src
I have the problem that the string that contains the file name is not returned. Thus, I don't get something like:
#+RESULTS:
[[file:images/myfig.pdf]]
Here is what I can see in the session's buffer:
Process Python finished
Python 3.4.3 (default, Feb 27 2015, 00:22:26)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> >>> >>> r/folders/kz/1c2cxn1x60n_t5p2j1p02b180000gn/T/py6499_X0''', 'exec'));
import matplotlib
>>> import matplotlib
matplotlib.use('Agg')
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
fig=plt.figure(figsize=(3,2))
fig=plt.figure(figsize=(3,2))
plt.plot([1,3,2])
plt.plot([1,3,2])
fig.tight_layout()
fig.tight_layout()
plt.savefig('myfig.pdf')
plt.savefig('myfig.pdf')
'myfig.pdf' # return this to org-mode
'myfig.pdf' # return this to org-mode
open('/var/folders/kz/1c2cxn1x60n_t5p2j1p02b180000gn/T/babel-64998Up/python-6499xhD', 'w').write(str(_))
open('/var/folders/kz/1c2cxn1x60n_t5p2j1p02b180000gn/T/babel-64998Up/python-6499xhD', 'w').write(str(_))
'org_babel_python_eoe'
'org_babel_python_eoe'
>>> [<matplotlib.lines.Line2D object at 0x10bc987f0>]
>>> >>> 'myfig.pdf'
>>> >>> 9
>>> >>> >>> 'org_babel_python_eoe'
>>>
However, the following works as expected:
#+begin_src python :session :results file
'./myfig.pdf' # return this to org-mode
#+end_src
#+RESULTS:
[[file:./myfig.pdf]]
What is the problem here? How can I debug it? It seems like matplotlib
causes some problem.