seaborn线性关系数据可视化:时间线图|热图|结构化图表可视化
一、線性關(guān)系數(shù)據(jù)可視化lmplot( )
表示對所統(tǒng)計(jì)的數(shù)據(jù)做散點(diǎn)圖,并擬合一個一元線性回歸關(guān)系。
lmplot(x, y, data, hue=None, col=None, row=None, palette=None,col_wrap=None, height=5, aspect=1,markers="o",
? ? sharex=True,sharey=True, hue_order=None, col_order=None,row_order=None,legend=True, legend_out=True,
? ? ? ? ? x_estimator=None, x_bins=None,x_ci="ci", scatter=True, fit_reg=True, ci=95, n_boot=1000,units=None, order=1,
? ? ? ? ? logistic=False, lowess=False, robust=False,logx=False, x_partial=None, y_partial=None, truncate=False,x_jitter=None,
? ? ? ? ? y_jitter=None, scatter_kws=None, line_kws=None,?size=None)
- x和y 表示顯示x和y的線性關(guān)系
- hue 表示對x按照hue進(jìn)行分類,每個分類都在同一個圖表顯示
- hue_order 按照hue分類后,多分類的結(jié)果進(jìn)行篩選和顯示排序
- col和row 表示對hue的分類拆分為多個圖表顯示,或者對x按照col分類并拆分為多個橫向的獨(dú)立圖表、或者對x按照row分類并拆分為多個豎直的獨(dú)立圖表
- col_order和row_order 按照col和row分類拆分后,多分類進(jìn)行刪選和顯示排序
- col_wrap 每行顯示的圖表個數(shù)
- height 每個圖表的高度(最后一個參數(shù)size即height,size正被height替代)
- aspect 每個圖表的長寬比,默認(rèn)為1即顯示為正方形
- marker 點(diǎn)的形式,
- sharex和sharey 拆分為多個圖表時是否共用x軸和y軸,默認(rèn)共用
- x_jitter和y_jitter 給x軸和y軸隨機(jī)增加噪點(diǎn)
?
sns.lmplot(x="tip", y="total_bill",data=tips,col='time',row='sex',height=3) #行拆分和列拆分二、時間線圖lineplot()
時間線圖用lineplot()表示,tsplot()正在被替代。
lineplot(x=None, y=None, hue=None, size=None, style=None, data=None, palette=None, hue_order=None, hue_norm=None,
? ? ? ? ? ? sizes=None, size_order=None, size_norm=None,dashes=True, markers=None, style_order=None,units=None,
? ? ? ? ? ? estimator="mean", ci=95, n_boot=1000,sort=True, err_style="band", err_kws=None,legend="brief", ax=None, **kwargs)
? ?
?
三、熱圖heatmap()
熱圖只針對二維數(shù)據(jù),用顏色的深淺表示大小,數(shù)值越小顏色越深。
heatmap(data, vmin=None, vmax=None, cmap=None, center=None, robust=False,annot=None, fmt=".2g",
? ? ? ? ? ? ? annot_kws=None,linewidths=0, linecolor="white",cbar=True, cbar_kws=None, cbar_ax=None,
? ? ? ? ? ? ? square=False, xticklabels="auto", yticklabels="auto",mask=None, ax=None, **kwargs)
- data 二維數(shù)據(jù)
- vmin和vmax 調(diào)色板的最小值和最大值
- annot 圖中是否顯示數(shù)值
- fmt 格式化數(shù)值
- linewidth和linecolor 格子線寬和顏色
- cbar 是否顯示色帶?
- cbar_kws 色帶的參數(shù)設(shè)置,字典形式,在cbar設(shè)置為True時才生效,例如{"orientation": "horizontal"}表示橫向顯示色帶
- square 每個格子是否為正方形
生成半邊熱圖,mask參數(shù)
rs = np.random.RandomState(33) d = pd.DataFrame(rs.normal(size=(100, 26))) corr = d.corr() #求解相關(guān)性矩陣表格,26*26的一個正方數(shù)據(jù) mask = np.zeros_like(corr, dtype=np.bool) mask[np.triu_indices_from(mask)] = True # 設(shè)置一個“上三角形”蒙版 cmap = sns.diverging_palette(220, 10, as_cmap=True)# 設(shè)置調(diào)色盤 sns.heatmap(corr, mask=mask, cmap=cmap, vmax=.3, center=0,square=True, linewidths=0.2)?
四、結(jié)構(gòu)化圖表可視化
tips = sns.load_dataset("tips") # 導(dǎo)入數(shù)據(jù) g = sns.FacetGrid(tips, col="time", row="smoker")# 創(chuàng)建一個繪圖表格區(qū)域,列按time分類、行按smoker分類 g.map(plt.hist, "total_bill",alpha = 0.5,color = 'b',bins = 10) # 以total_bill字段數(shù)據(jù)分別做直方圖統(tǒng)計(jì)?
g = sns.FacetGrid(tips, col="day", height=4, # 圖表大小aspect=.8) # 圖表長寬比 g.map(plt.hist, "total_bill", bins=10,histtype = 'step', #'bar', 'barstacked', 'step', 'stepfilled'color = 'k')?
#散點(diǎn)圖 g = sns.FacetGrid(tips, col="time", row="smoker")g.map(plt.scatter, "total_bill", "tip", # share{x,y} → 設(shè)置x、y數(shù)據(jù)edgecolor="w", s = 40, linewidth = 1) # 設(shè)置點(diǎn)大小,描邊寬度及顏色?
g = sns.FacetGrid(tips, col="time", hue="smoker") # 創(chuàng)建一個繪圖表格區(qū)域,列按col分類,按hue分類 g.map(plt.scatter, "total_bill", "tip", # share{x,y} → 設(shè)置x、y數(shù)據(jù)edgecolor="w", s = 40, linewidth = 1) # 設(shè)置點(diǎn)大小,描邊寬度及顏色 g.add_legend()?
attend = sns.load_dataset("attention") print(attend.head())g = sns.FacetGrid(attend, col="subject", col_wrap=5,# 設(shè)置每行的圖表數(shù)量size=1.5) g.map(plt.plot, "solutions", "score", marker="o",color = 'gray',linewidth = 2)# 繪制圖表矩陣 g.set(xlim = (0,4),ylim = (0,10),xticks = [0,1,2,3,4], yticks = [0,2,4,6,8,10]) # 設(shè)置x,y軸刻度?
轉(zhuǎn)載于:https://www.cnblogs.com/Forever77/p/11410065.html
總結(jié)
以上是生活随笔為你收集整理的seaborn线性关系数据可视化:时间线图|热图|结构化图表可视化的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 周公解梦梦到自己掉牙齿是什么预兆
- 下一篇: 昨夜梦到大蛇伤人怎么回事