2 回答

TA贡献1799条经验 获得超8个赞
在代码的末尾和开头添加,在我的计算机上创建一个完全有效的图片:plt.savefig("test.png")
import matplotlib.pyplot as plt
以下是完整的脚本:
import matplotlib.pyplot as plt
x = range(-300, 1)
x_2 = range(0, 301)
y = range(-300, 1)
y_2 = range(0, 301)
x_1 = range(-300, 1)
y_3 = range(0, -301, -1)
x_3 = range(0, -301, -1)
x_0 = [0 for i in range(301)]
y_0 = [0 for i in range(301)]
plt.plot(x_2, y_2, label="direction 1")
plt.plot(x_2, y_3, label="direction 2")
plt.plot(x_1, y, label="direction 3")
plt.plot(x_3, y_2, label="direction 4")
plt.plot(x_0, y_2, label="direction 5")
plt.plot(x_0, y, label="direction 6")
plt.plot(x_2, y_0, label="direction 7")
plt.plot(x, y_0, label="direction 8")
plt.legend(loc="best")
plt.xlabel("x")
plt.ylabel("y")
plt.savefig("test.png")
添加回答
举报