Matplotlib is the toolkit, Pyplot is an interactive way to use Matplotlib and PyLab is the same thing as PyPlot but with some extra shortcuts. Using PyLab is discouraged now.
- Matplotlib: It's a Python plotting library, inspired by MATLAB, meaning that the terms used (Axis, Figure, Plots) will be similar to those used in MATLAB.
- Pyplot: It's a shell-like interface to Matplotlib, to make it easier to use for people who are used to MATLAB. (Import via
matplotlib.pyplot
namespace) - Pylab: Combining both the PyPlot and NumPy namespaces into a single one (to avoid having to import two namespaces), the result is PyLab.
Pyplot recommended鳞绕,因?yàn)樗兇狻?/p>
fig=plt.figure() 創(chuàng)建figure對象岭皂。其中figsize選項(xiàng)可以用于當(dāng)前圖片保存到磁盤的時(shí)候具有一定的大小和縱橫比蚊惯。
Subplot
不能通過空Figure繪圖蕊肥。
ax1=fig.add_subplot(2,2,1) 可以添加多個(gè)subplot蜀撑。這個(gè)代碼的意思是圖像是2x2的,當(dāng)前選中的是4個(gè)當(dāng)中的第一個(gè)褥伴。如果此時(shí)發(fā)出繪圖命令返吻,則會(huì)在最后一個(gè)圖上進(jìn)行繪制。(若沒有,則創(chuàng)建一個(gè)肠阱。)
Legend
圖利(legend)是一種用于標(biāo)示圖標(biāo)元素的重要工具票唆。
可以通過 ax.legend() 或者 plt.legend() 來自動(dòng)創(chuàng)建圖例。
選項(xiàng)loc表示位置屹徘。
0: ‘best'
1: ‘upper right'
2: ‘upper left'
3: ‘lower left'
4: ‘lower right'
5: ‘right'
6: ‘center left'
7: ‘center right'
8: ‘lower center'
9: ‘upper center'
10: ‘center'
fontsize設(shè)置字體大小走趋。
fontsize : int or float or {‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’}
frameon = False 表示去掉圖例邊框
edgecolor = 'blue' 來設(shè)置圖例邊框的顏色
facecolor = 'red' 來設(shè)置圖例背景的顏色, 若無邊框,參數(shù)無效
title 設(shè)置圖例標(biāo)題
markerscale 圖例標(biāo)記與原始標(biāo)記的相對大小
ncol 把圖例分為n例顯示
columnspacing 列間距
labelspacing 圖例條目之間的垂直間距
更多語法參數(shù)參考:https://blog.csdn.net/qq_33221533/article/details/81431264
Scatter
ax.scatter()
繪制散布圖的函數(shù)噪伊。
s對應(yīng)每個(gè)點(diǎn)的大小簿煌,c對應(yīng)顏色。
marker表示散點(diǎn)的形狀鉴吹。
詳見:http://www.reibang.com/p/53e49c02c469
繪制簡單圖形
plt.title() #設(shè)置圖標(biāo)標(biāo)題
ax.xlable() #設(shè)置坐標(biāo)軸x標(biāo)簽
ax.ylable()
ax.tick_params(axis='x',labelsize=20) #設(shè)置刻度標(biāo)記的大小
ax.tick_params(axis='y',labelsize=20)
plt.show() #打開matplotlib查看器姨伟,并顯示繪制圖形
保存
fig.savefig()
坐標(biāo)刻度
plt.xticks([]) # 關(guān)閉坐標(biāo)刻度
plt.axis('off') # 關(guān)閉坐標(biāo)軸
參考: https://blog.csdn.net/lanchunhui/article/details/52931883