在使用matplotlib时遇到这样一个问题,画图时运行程序但是没有显示出来,代码如下。
import matplotlib.pyplot as plt
plt.plot([10, 20, 30])
plt.xlabel('tiems')
plt.ylabel('numbers')
plt.show()
这种情况是没有安装wx等gui环境,如我们可以使用下面的命令安装wx。
sudo apt-get install python-wxgtk3.0
安装成功后,在原代码里加入matplotlib.use(‘WXagg’)即可。
import matplotlib
matplotlib.use('WXagg')
import matplotlib.pyplot as plt
plt.plot([10, 20, 30])
plt.xlabel('tiems')
plt.ylabel('numbers')
plt.show()
运行结果如下所示
参考
[1] http://bbs.youkuaiyun.com/topics/391953578
[2] http://www.yiibai.com/wxpython/wxpython_environment.html