Matplotlib Pyplot 在 Ubuntu 16.04 上中断

Matplotlib Pyplot breaks on Ubuntu 16.04

我目前在 Ubuntu 16.04 上使用 Python 2.7,并且希望能够使用 Matplotlib 绘制图形。但是,调用任何类型的 plot 命令都会导致整个脚本在该行挂起。

** 注意 ** 在将此标记为重复问题之前,请考虑此问题可能与我正在使用的后端无关,因为我已经尝试了我在互联网上找到的此解决方案的每一次迭代.

一个简单的脚本来说明我的问题:

#!/usr/bin/env python
import matplotlib
matplotlib.use('TkAgg')
from matplotlib import pyplot as plt
plt.interactive('True')


if __name__ == '__main__':

    print 'Hello World!'
    plt.figure()
    print 'Hello Again World!'

以上脚本的输出为:Hello World!

然后脚本挂在 plt.figure() 行,导致 100% cpu 使用率,并且无法使用 Ctrl-C 终止。我使用 "kill" 终止该进程。

我从来没有弄清楚是什么导致了我的问题,但我的(糟糕的)解决方案是重新安装 Ubuntu 16.04,然后重新安装 matplotlib。现在一切正常。

谢谢大家!