Linux服务器没有图形界面,无法使用matplotlib.plt.show()和matplotlib.plt.plot()函数
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
xpoints = np.array([0, 6])
ypoints = np.array([0, 100])
plt.plot(xpoints, ypoints)
#plt.show()
plt.savefig("save_pics/image1.png")
plt.close()
xpoints = np.array([1, 2, 6, 8])
ypoints = np.array([3, 8, 1, 10])
plt.plot(xpoints, ypoints)
plt.savefig("save_pics/image2.png")
plt.close()
如果需要绘制多个图片,记得在每一个 savefig 下面接一个 close ,不然会重叠。