简体   繁体   English

python matplotlib Agg与交互式绘图和tight_layout

[英]python matplotlib Agg vs. interactive plotting and tight_layout

If I use the Agg backend, I'm unable to keep image windows open with show() (regardless of block=True or not)---they just close virtually immediately. 如果我使用Agg后端,我无法使用show()打开图像窗口(无论block=True还是不) - 它们几乎立即关闭。 If I don't use Agg , then I get the warning: 如果我不使用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")

Sample code: 示例代码:

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()

Is there a different backend or methodology I should be using? 我应该使用不同的后端或方法吗?

@FilipeCorreia在评论中给出的解决方法是删除mpl.use('Agg') ,并使用fig.set_tight_layout(True)代替fig.tight_layout()

Agg is a non-interactive backend , meaning it won't display on the screen, only save to files. Agg是一个非交互式后端 ,这意味着它不会显示在屏幕上,只保存到文件中。 Which backend are you using? 你使用的是哪个后端? You have OSX, perhaps you can try the 'macosx', or an interactive backend that uses Agg (eg. QT4Agg, WXAgg). 你有OSX,也许你可以试试'macosx',或者使用Agg的交互式后端(例如QT4Agg,WXAgg)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM