【发布时间】:2015-09-21 02:17:38
【问题描述】:
考虑以下带有 babel 的 org-mode 中的 python 代码块:
#+begin_src python :results none
import numpy as np
import matplotlib as mpl
from matplotlib import pyplot as plt
graylevel = 0.75
mpl.rc('figure', facecolor = (graylevel, graylevel, graylevel), edgecolor ='r')
X = np.linspace(0, 7, 1024)
plt.plot(X, np.sin(X))
plt.plot(X, np.cos(X))
plt.draw()
plt.show()
#+end_src]
在弹出窗口中,这会产生一个灰色背景的图
但是,将绘图放入文件时,再次处于 org 模式(只有最后几行不同)
#+begin_src python :results file
import numpy as np
import matplotlib as mpl
from matplotlib import pyplot as plt
graylevel = 0.75
mpl.rc('figure', facecolor = (graylevel, graylevel, graylevel), edgecolor ='r')
X = np.linspace(0, 7, 1024)
plt.plot(X, np.sin(X))
plt.plot(X, np.cos(X))
plt.draw()
plt.savefig('test.png')
return 'test.png'
#+end_src
#+RESULTS:
[[file:test.png]]
灰色背景消失了
我确实需要灰色背景来从 org-mode 导出我的图,因为我需要从周围文档中设置的图。
我不知道这是 matplotlib、org-mode、python、我的机器还是我自己的问题。我希望有人可以复制这个例子,或者也许只是知道答案。
【问题讨论】:
标签: python matplotlib org-mode