使用到的方法
- plt.figure() //可以理解爲聲明窗口
- plt.plot() // 線的座標值
- plt.show() // 顯示
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-1,1,50) //取值範圍以及點數
y = 2*x+1 //方程
plt.figure(num=4, figsize=(4,3)) // 窗口名稱 和 大小
plt.plot(x,y, color='red', linewidth=4) // 畫線
plt.show()
多條線
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-1,1,50)
y1 = x**2
y2 = 2*x+1
plt.figure(num=4, figsize=(4,3))
plt.plot(x,y1, color='red', linewidth=2)
plt.plot(x,y2, color='green', linewidth=2, linestyle='--')
plt.show()
多窗口
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-1,1,50)
y1 = x**2
y2 = 2*x+1
plt.figure(num=4, figsize=(4,3))
plt.plot(x,y1, color='red', linewidth=2)
plt.figure(num=1, figsize=(4,3))
plt.plot(x,y2, color='red')
plt.show()