【问题标题】:Matplotlib stopped working after upgrade to 1.1.0Matplotlib 升级到 1.1.0 后停止工作
【发布时间】:2012-03-11 18:11:58
【问题描述】:

我正在尝试在 Ubuntu 11.10 下运行 matplotlib 1.1.0。我之前安装并运行了 matplotlib 1.0.1,但我需要 1.1.0 版中的一些功能(而且我很生气,因为所有文档都是针对我的另一个版本的)所以我决定升级。

现在,我无法显示任何情节。

我已经卸载了包存储库中的所有内容,以及installed version 1.1.0 from source。我已经阅读了installation FAQ,但那里的提示没有帮助。我从他们建议的故障排除程序中得到以下输出,但没有情节:

$HOME=/home/tomas
CONFIGDIR=/home/tomas/.matplotlib
matplotlib data path /usr/local/lib/python2.7/dist-packages/matplotlib/mpl-data
loaded rc file /usr/local/lib/python2.7/dist-packages/matplotlib/mpl-data/matplotlibrc
matplotlib version 1.1.0
verbose.level helpful
interactive is False
platform is linux2
Using fontManager instance from /home/tomas/.matplotlib/fontList.cache
backend agg version v2.2

我需要做什么才能让它工作?

更新:
在跟进 cmets 中的一些故障排除技巧后,我可以报告说,实际显示的图不起作用。

运行以下脚本会输出一个带有预期绘图的 png,但不显示任何绘图窗口。

from matplotlib import pyplot as plt
plt.plot([1, 2, 3])
plt.savefig('testfig.png')
plt.show()

【问题讨论】:

  • 它会给你任何错误信息吗?
  • @ThomasK:不,它只是默默地没有显示任何情节。
  • 您在安装新版本之前是否删除了旧版本?
  • 你试过不同的后端吗?您可以使用plt.savefig('test.pdf') 将绘图写入文件吗?
  • @Zhenya:是的,我做到了。在从源代码安装之前,我使用sudo apt-get remove python-matplotlib 取消了停滞,还做了find / -ipath "*matplotlib*" 并删除了任何不是1.1.0 安装文件的内容。它没有帮助。

标签: python matplotlib ubuntu-11.10


【解决方案1】:

当您导入pyplot 时,它必须设置一个后端,并且可能将其设置为非交互式的,这可以解释您所看到的行为。通过运行plt.get_backend()查看正在使用的后端

要设置后端,您必须在导入pyplot 之前运行这些命令

import matplotlib
matplotlib.use(your_backend)

在哪里

your_backend in set(["FLTKAgg", "GTK", "GTKAgg", "GTKCairo", "macosx",
                    "QTAgg", "QT4Agg", "TkAgg", "WX", "WXAgg"])

要使其成为永久设置,请将后端名称(不带引号)放入您的 ~/.matplotlib/matplotlibrc 文件中,如下例所示:

backend       : WXAgg

【讨论】:

    最近更新 更多