seaborn線性關系數據可視化:時間線圖|熱圖|結構化圖表可視化

一、線性關系數據可視化lmplot( )

表示對所統計的數據做散點圖,并擬合一個一元線性回歸關系。

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的線性關系
  • hue 表示對x按照hue進行分類,每個分類都在同一個圖表顯示
  • hue_order 按照hue分類后,多分類的結果進行篩選和顯示排序
  • col和row 表示對hue的分類拆分為多個圖表顯示,或者對x按照col分類并拆分為多個橫向的獨立圖表、或者對x按照row分類并拆分為多個豎直的獨立圖表
  • col_order和row_order 按照col和row分類拆分后,多分類進行刪選和顯示排序
  • col_wrap 每行顯示的圖表個數
  • height 每個圖表的高度(最后一個參數size即height,size正被height替代)
  • aspect 每個圖表的長寬比,默認為1即顯示為正方形
  • marker 點的形式,
  • sharex和sharey 拆分為多個圖表時是否共用x軸和y軸,默認共用
  • x_jitter和y_jitter 給x軸和y軸隨機增加噪點
#hue分類,col圖表拆分
sns.lmplot(x="tip", y="total_bill",data=tips,hue='smoker',palette="Set1",ci = 80, markers = ['+','o'])  #是否吸煙在同一個圖表顯示
sns.lmplot(x="tip", y="total_bill",data=tips,hue='day',col='day',sharex=True,markers='.')  #按日期拆分為獨立的圖表

?

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)

fmri = sns.load_dataset("fmri")
ax = sns.lineplot(x="timepoint", y="signal", data=fmri)
fmri.head()

? ?

?

三、熱圖heatmap()

熱圖只針對二維數據,用顏色的深淺表示大小,數值越小顏色越深。

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 二維數據
  • vmin和vmax 調色板的最小值和最大值
  • annot 圖中是否顯示數值
  • fmt 格式化數值
  • linewidth和linecolor 格子線寬和顏色
  • cbar 是否顯示色帶?
  • cbar_kws 色帶的參數設置,字典形式,在cbar設置為True時才生效,例如{"orientation": "horizontal"}表示橫向顯示色帶
  • square 每個格子是否為正方形
rng = np.random.RandomState(1)
df = pd.DataFrame(rng.randint(1,10,(10,12)))
fig = plt.figure(figsize=(15,6))
ax1 = plt.subplot(121)
sns.heatmap(df,vmin=3,vmax=8,linewidth=0.2,square=True)
ax2 = plt.subplot(122)
sns.heatmap(df,annot=True,square=False,cbar_kws={"orientation": "horizontal"})

生成半邊熱圖,mask參數

rs = np.random.RandomState(33)
d = pd.DataFrame(rs.normal(size=(100, 26)))
corr = d.corr() #求解相關性矩陣表格,26*26的一個正方數據

mask = np.zeros_like(corr, dtype=np.bool)
mask[np.triu_indices_from(mask)] = True
# 設置一個“上三角形”蒙版

cmap = sns.diverging_palette(220, 10, as_cmap=True)# 設置調色盤

sns.heatmap(corr, mask=mask, cmap=cmap, vmax=.3, center=0,square=True, linewidths=0.2)

?

四、結構化圖表可視化

tips = sns.load_dataset("tips")  # 導入數據
g = sns.FacetGrid(tips, col="time", row="smoker")#  創建一個繪圖表格區域,列按time分類、行按smoker分類
g.map(plt.hist, "total_bill",alpha = 0.5,color = 'b',bins = 10) # 以total_bill字段數據分別做直方圖統計

?

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')

?

#散點圖
g = sns.FacetGrid(tips, col="time",  row="smoker")g.map(plt.scatter, "total_bill", "tip",    # share{x,y} → 設置x、y數據edgecolor="w", s = 40, linewidth = 1)   # 設置點大小,描邊寬度及顏色

?

g = sns.FacetGrid(tips, col="time", hue="smoker") # 創建一個繪圖表格區域,列按col分類,按hue分類

g.map(plt.scatter, "total_bill", "tip",    # share{x,y} → 設置x、y數據edgecolor="w", s = 40, linewidth = 1)   # 設置點大小,描邊寬度及顏色
g.add_legend()

?

attend = sns.load_dataset("attention")
print(attend.head())g = sns.FacetGrid(attend, col="subject", col_wrap=5,# 設置每行的圖表數量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]) # 設置x,y軸刻度

?

轉載于:https://www.cnblogs.com/Forever77/p/11410065.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/391548.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391548.shtml
英文地址,請注明出處:http://en.pswp.cn/news/391548.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

hdu 1257

http://acm.hdu.edu.cn/showproblem.php?pid1257 題意:有個攔截系統,這個系統在最開始可以攔截任意高度的導彈,但是之后只能攔截不超過這個導彈高度的導彈,現在有N個導彈需要攔截,問你最少需要多少個攔截系統 思路&am…

eda可視化_5用于探索性數據分析(EDA)的高級可視化

eda可視化Early morning, a lady comes to meet Sherlock Holmes and Watson. Even before the lady opens her mouth and starts telling the reason for her visit, Sherlock can tell a lot about a person by his sheer power of observation and deduction. Similarly, we…

我的AWS開發人員考試未通過。 現在怎么辦?

I have just taken the AWS Certified Developer - Associate Exam on July 1st of 2019. The result? I failed.我剛剛在2019年7月1日參加了AWS認證開發人員-聯考。結果如何? 我失敗了。 The AWS Certified Developer - Associate (DVA-C01) has a scaled score …

關系數據可視化gephi

表示對象之間的關系,可通過gephi軟件實現,軟件下載官方地址https://gephi.org/users/download/ 如何來表示兩個對象之間的關系? 把對象變成點,點的大小、顏色可以是它的兩個參數,兩個點之間的關系可以用連線表示。連線…

Hyperledger Fabric 1.0 從零開始(十二)——fabric-sdk-java應用

Hyperledger Fabric 1.0 從零開始(十)——智能合約(參閱:Hyperledger Fabric Chaincode for Operators——實操智能合約) Hyperledger Fabric 1.0 從零開始(十一)——CouchDB(參閱&a…

css跑道_如何不超出跑道:計劃種子的簡單方法

css跑道There’s lots of startup advice floating around. I’m going to give you a very practical one that’s often missed — how to plan your early growth. The seed round is usually devoted to finding your product-market fit, meaning you start with no or li…

將json 填入表格_如何將Google表格用作JSON端點

將json 填入表格UPDATE: 5/13/2020 - New Share Dialog Box steps available below.更新:5/13/2020-下面提供了 新共享對話框步驟。 Thanks Erica H!謝謝埃里卡H! Are you building a prototype dynamic web application and need to collaborate with …

leetcode 173. 二叉搜索樹迭代器

實現一個二叉搜索樹迭代器類BSTIterator ,表示一個按中序遍歷二叉搜索樹(BST)的迭代器: BSTIterator(TreeNode root) 初始化 BSTIterator 類的一個對象。BST 的根節點 root 會作為構造函數的一部分給出。指針應初始化為一個不存在…

jyputer notebook 、jypyter、IPython basics

1 、修改jupyter默認工作目錄:打開cmd,在命令行下指定想要進的工作目錄,即鍵入“cd d/ G:\0工作面試\學習記錄”標紅部分是想要進入的工作目錄。 2、Tab補全 a、在命令行輸入表達式時,按下Tab鍵即可為任意變量(對象、…

cookie和session(1)

cookie和session 1.cookie產生 識別用戶 HTTP是無狀態協議,這就回出現這種現象:當你登錄一個頁面,然后轉到登錄網站的另一個頁面,服務器無法認識到。或者說兩次的訪問,服務器不能認識到是同一個客戶端的訪問&#xff0…

熊貓數據集_為數據科學拆箱熊貓

熊貓數據集If you are already familiar with NumPy, Pandas is just a package build on top of it. Pandas provide more flexibility than NumPy to work with data. While in NumPy we can only store values of single data type(dtype) Pandas has the flexibility to st…

2018年,你想從InfoQ獲取什么內容?丨Q言Q語

- Q 言 Q 語 第 三 期 - Q言Q語是 InfoQ 推出的最新板塊, 旨在給所有 InfoQer 一個展示觀點的平臺。 每期一個主題, 不扣帽子,不論對錯,不看輸贏, 只愿跟有趣的靈魂相遇。 本期話題: 2018年,你想…

特征阻抗輸入阻抗輸出阻抗_軟件阻抗說明

特征阻抗輸入阻抗輸出阻抗by Milan Mimica米蘭米米卡(Milan Mimica) 軟件阻抗說明 (Software impedance explained) 數據處理組件之間的阻抗不匹配 (The impedance mismatch between data processing components) It all starts with the simplest signal-processing diagram …

數學建模3

數學建模3 轉載于:https://www.cnblogs.com/Forever77/p/11423169.html

leetcode 190. 顛倒二進制位(位運算)

顛倒給定的 32 位無符號整數的二進制位。 提示: 請注意,在某些語言(如 Java)中,沒有無符號整數類型。在這種情況下,輸入和輸出都將被指定為有符號整數類型,并且不應影響您的實現,因…

JAVA基礎——時間Date類型轉換

在java中有六大時間類,分別是: 1、java.util包下的Date類, 2、java.sql包下的Date類, 3、java.text包下的DateFormat類,(抽象類) 4、java.text包下的SimpleDateFormat類, 5、java.ut…

LeetCode第五天

leetcode 第五天 2018年1月6日 22.(566) Reshape the Matrix JAVA class Solution {public int[][] matrixReshape(int[][] nums, int r, int c) {int[][] newNums new int[r][c];int size nums.length*nums[0].length;if(r*c ! size)return nums;for(int i0;i<size;i){ne…

matplotlib可視化_使用Matplotlib改善可視化設計的5個魔術技巧

matplotlib可視化It is impossible to know everything, no matter how much our experience has increased over the years, there are many things that remain hidden from us. This is normal, and maybe an exciting motivation to search and learn more. And I am sure …

adb 多點觸碰_無法觸及的神話

adb 多點觸碰On Twitter, in Slack, on Discord, in IRC, or wherever you hang out with other developers on the internet, you may have heard some formulation of the following statements:在Twitter上&#xff0c;在Slack中&#xff0c;在Discord中&#xff0c;在IRC…

robot:循環遍歷數據庫查詢結果是否滿足要求

使用list類型變量{}接收查詢結果&#xff0c;再for循環遍歷每行數據&#xff0c;取出需要比較的數值 轉載于:https://www.cnblogs.com/gcgc/p/11424114.html