组织模式babel python会话和内联图像不兼容?

时间:2013-04-21 16:28:34

标签: org-mode

如果我使用此块

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

然后结果块显示了该图的内联版本。

如果现在我切换到此块

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

然后结果块没有显示内联图,但是这个

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

使用会话对我来说是强制性的,因为我需要几个块来共享变量。

我的方法有明显错误吗?

1 个答案:

答案 0 :(得分:2)

根据org-mode documentation,如果代码在会话中运行,则必须删除return

#+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]]

因为“返回的结果是解释器执行的最后一次评估的结果。”

相关问题