UserWarning: Matplotlib is currently using agg, which is a non-GUI backend
背景
python的Matlibplot库很实用方便,我等公司程序员(Gis专业相关)经常实用这个库作为辅助调试工具。
公司最近给我换了电脑。安装pycharm后,跑了下原先的程序,发现报错了,程序如下:
import matplotlib.pyplot as plt
x1 = [0, 150, 250, 250, 150, 100, 0, 0]
y1 = [2.03, 7.9, 11.5, 0.8, -0.1, -0.9, -2.47, 2.03]
x2 = [0, 100, 150, 250, 250, 150, 0, 0]
y2 = [-2.47, -0.9, -0.1, 0.8, -8, -7, -5.85, -2.47]
x3 = [0, 150, 250, 250, 150, 0, 0]
y3 = [-5.85, -7, -8, -15, -12, -9.292 ,-5.85]
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x1, y1, color='darkgreen')
ax.plot(x2, y2, color='red')
ax.plot(x3, y3, color='yellow')
plt.show()
报错如下:
UserWarning: Matplotlib is currently using agg, which is a non-GUI backend
解决方法
查阅google,翻到了stackoverflow ,
需要安装ActiveTCL(下载地址),然后关联python3
sudo ./configure --with-tcltk-includes='-I/....../ActiveTcl8.6/include' --with-tcltk-libs='....../ActiveTcl8.6/lib/libtcl8.6.so ....../ActiveTcl8.6/lib/libtk8.6.so'
sudo make && sudo make install
操作完成后,运行如下python代码可以测试有无安装成功,展示了简单的GUI页面则成功。
import tkinter
tkinter._test()