Python3學習-Matplotlib(1)
阿新 • • 發佈:2018-12-20
Matplotlib安裝
dos命令下----執行:Python -m pip install matplotlib
安裝後: 測試程式碼:
import matplotlib as plt
import numpy as np
x = np.linspace(1, 50)
y = 2*x + 1
plt.plot(x, y)
plt.show()
顯示:
figure影象
import matplotlib as plt
import numpy as np
x = np.linspace(-1, 1, 50)
y1 = 2*x + 1
y2 = x**2
plt.figure ()
plt.plot(x, y1)
plt.figure()
plt.plot(x, y2)
plt.show()
效果:
修改figuer名:
plt.figure(num = 6)
效果:
修改figuer尺寸:
plt.figure(num = 6, figsize=(5, 4))
效果:
使figuer多資料:
plt.figure(num = 6, figsize=(5, 4))
plt.plot(x, y2)
plt.plot(x, y1)
效果:
修改線條引數: color-顏色 linewidth-寬度 linestyle-線條風格
plt.plot (x, y1, color = 'red', linewidth = 1.0, linestyle = '--' )
效果: