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")
添加回答
舉報
