解决自己编译的 python 运行绘图时报错如下:
UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure. plt.show()
根据自己的实际经验,需要如下几步:
- 安装 tcl-devel 和 tk-devel 软件包
- 重新从 python 源码配置一遍,然后编译安装
就可以了,我的测试代码:
#!/usr/bin/python
import matplotlib
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
#matplotlib.use('TkAgg')
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x3=[0,10,10,20,30,40,50,60,70,80,90,100,100,100,100,100,100,100,100,100,100,100,100,100]
y3=[35,36.9,40,45,46,47,48,49,50,51,52,53,54,55,56,67,58,59,60,61,62,63,64,65]
z3=[32.3,38.95,46.59,52.9,54,56.93,58.92,59.93,60.96,61.98,64.7,65.13,66.19,66.19,66.19,67.27,67.27,67.27,67.27,67.27,67.27,68.35,68.35,69.44]
print(len(x3), len(y3), len(z3))
ax.plot(x3,y3,z3,label='hello')
plt.show()