Matplotlib入門
Matplotlib繪圖庫
Figure對象 figure(num,figsize,dpi,facecolor,edgecolor,frameon)
num:圖形編號/名稱,取值為數(shù)字/字符串
figsize:繪圖對象的寬和高,單位為英寸
dpi:繪圖對象分辨率,缺省值為80
facecolor:背景顏色
edgecolor:邊框顏色
frameon:是否顯示邊框
Figure對象-劃分子圖 subplot(行數(shù),列數(shù),子圖序號)
1 1 2 1 2 3 從左到右 從上到下編號
2 3 4 4 5 6
設置中文字體
plt.rcParams["font.sans-serif"] = "SimHei"
rcParams-運行配置參數(shù) run configuration Params
SimHei 中文黑體
SimSun 宋體
Microsoft YaHei 微軟雅黑
Microsoft JhengHei 微軟正黑
KaiTi 楷體
FangSong 仿宋
LiSu 隸書
YouYuan 幼圓
plt.rcdefaults()恢復標準默認
添加標題
全局標題
suptitle(標題文字)
x 標題位置的x坐標
y 標題位置的y坐標
.
.
.
horizontalalignment 水平對齊方式 center
verticalalignment 垂直對齊方式 top
子標題
title(標題文字)
文字
text(x,y,s,fontsize,color)
tight_layout()
自動調(diào)整子圖,使其填充整個繪圖區(qū)域,并消除子圖之間的重疊
散點圖(Scatter)
scatter(x,y,scale,color,marker,label)
scale:數(shù)據(jù)點大小 默認36
marker:數(shù)據(jù)點樣式 默認為 o
坐標軸設置
plt.rcParams["axes.unicode_minus"] = False
xlabel(x,y,s,fontsize,color)
ylabel(x,y,s,fontsize,color)
xlim(xmin,xmax)
ylim(ymin,ymax)
tick_params(labelsize)
增加圖例
scatter使用label標簽
legend(loc, fontsize)
loc參數(shù)表示圖例位置
折線圖(Line Chart)
描述變量變化的趨勢
plot(x,y,color,marker,label,linewidth,markersize)
柱狀圖(Bar Chart)
由一系列高度不等的柱形條紋表示數(shù)據(jù)分布的情況
bar(left,height,width,facecolor,edgecolor,label)
Matplotlib官網(wǎng)
matplotlib.org
matplotlib.org/genindex.html
Gallery頁面
matplotlib.org/gallery.html