如果我使用Agg
后端,我无法保持图像窗口打开show()
(无论是否block=True
)——它们几乎立即关闭。如果我不使用Agg
,那么我会收到警告:
/Library/Python/2.7/site-packages/matplotlib-1.2.0-py2.7-macosx-10.8-intel.egg/matplotlib/tight_layout.py:225: UserWarning: tight_layout : falling back to Agg renderer warnings.warn("tight_layout : falling back to Agg renderer")
示例代码:
import matplotlib as mpl
mpl.use('Agg') # With this line = figure disappears; without this line = warning
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111)
mu, sigma = 0, 0.5
x = np.linspace(-3, 3, 100)
plt.plot(x, mlab.normpdf(x, mu, sigma))
fig.tight_layout()
plt.show()
我应该使用不同的后端或方法吗?