目錄
1.首先,引入
import matplotlib.plot as plt
2.創建窗口並顯示
#最簡易寫法
plt.figure(1)
#...在中間加顯示其他線呀,點呀
plt.show()
明確plt.figure參數
figure(num=None, figsize=None, dpi=None, facecolor=None, edgecolor=None, frameon=True)
- num:圖像編號或名稱,數字爲編號 ,字符串爲名稱
- figsize:指定figure的寬和高,單位爲英寸;使用都是figsize=(100,100)
- dpi參數指定繪圖對象的分辨率,即每英寸多少個像素,缺省值爲80 1英寸等於2.5cm,A4紙是 21*30cm的紙張
- facecolor:背景顏色
- edgecolor:邊框顏色
- frameon:是否顯示邊框
3.繪製散點圖
plt.scatter(x_bound_1,y_bound_1,marker='^',c='y')
atplotlib.pyplot.scatter(x, y, s=None, c=None, marker=None, cmap=None, norm=None,
vmin=None, vmax=None, alpha=None, linewidths=None, verts=None, edgecolors=None, *,
plotnonfinite=False, data=None, **kwargs)[source]
#注意,這裏x,y可以是list,也可以是一個點數據
4.設置橫縱座標的取值範圍
axes = plt.gca()
axes.set_xlim(xmin,xmax)
axes.set_ylim(ymin,ymax)
5.設置橫縱座標刻度
plt.xticks(np.arange(1,1000,1))
plt.yticks(np.arange(1,1000,1))
xticks(ticks=None, labels=None, **kwargs)[source]
參數解釋:
ticks是一個數組數列
labels表示x-axis的刻度線顯示標註的地方,labels不賦值,在這些位置添加的數值即爲locs數組中的數
6.網格線設置
plt.grid()
matplotlib.pyplot.grid(b=None, which='major', axis='both', **kwargs)[source]
https://matplotlib.org/2.2.3/api/_as_gen/matplotlib.pyplot.grid.html#matplotlib.pyplot.grid
7.繪製線plt.plot()
plt.plot(x_list,y_list)
plt.plot(x,y,format_string,**kwargs)
x軸數據,y軸數據,format_string控制曲線的格式字串
format_string 由顏色字符,風格字符,和標記字符 即marker,line,color
https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot