国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

腳本之家,腳本語言編程技術(shù)及教程分享平臺!
分類導航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務器之家 - 腳本之家 - Python - Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

2021-05-15 00:43yhlp Python

這篇文章主要介紹了Python數(shù)據(jù)可視化庫seaborn的使用總結(jié),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

seaborn是python中的一個非常強大的數(shù)據(jù)可視化庫,它集成了matplotlib,下圖為seaborn的官網(wǎng),如果遇到疑惑的地方可以到官網(wǎng)查看。http://seaborn.pydata.org/

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

從官網(wǎng)的主頁我們就可以看出,seaborn在數(shù)據(jù)可視化上真的非常強大。

1.首先我們還是需要先引入庫,不過這次要用到的python庫比較多。

?
1
2
3
4
5
import numpy as np
import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns

2.sns.set_style():不傳入?yún)?shù)用的就是seaborn默認的主題風格,里面的參數(shù)共有五種

  • darkgrid
  • whitegrid
  • dark
  • white
  • ticks

我比較習慣用whitegrid。

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

3.下面說一下seaborn里面的調(diào)色板,我們可以用sns.color_palette()獲取到這些顏色,然后用sns.palplot()將這些色塊打印出來。color_palette()函數(shù)還可以傳入一些參數(shù)

?
1
2
3
4
5
6
7
8
9
sns.palplot(sns.color_palette("hls",n))#顯示出n個不同顏色的色塊
sns.palplot(sns.color_palette("paired",2n))#顯示出2n個不同顏色的色塊,且這些顏色兩兩之間是相近的
sns.palplot(sns.color_palette("color"))#由淺入深顯示出同一顏色的色塊
sns.palplot(sns.color_palette("color_r"))##由深入淺顯示出同一顏色的色塊
sns.palplot(sns.color_palette("cubehelix",n))#顯示出n個顏色呈線性變化的色塊
sns.palplot(sns.cubehelix_palette(k,start=m,rot=n))#顯示出k個start(0,3)為m,rot(-1,1)為n的呈線性變化的色塊
sns.palplot(sns.light_palette("color"))#將一種顏色由淺到深顯示
sns.palplot(sns.dark_palette("color"))#將一種顏色由深到淺顯示
sns.palplot(sns.dark_palette("color",reverse=bool))#reverse的值為false,則將一種顏色由深到淺顯示;若為true,則將一種顏色由淺到深顯示

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

4.sns.kdeplot(x,y,cmap=pal):繪制核密度分布圖。

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

5.sns.distplot(x,kde=bool,bins=n):kde代表是否進行核密度估計,也就是是否繪制包絡線,bins指定繪制的條形數(shù)目。

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

6.根據(jù)均值和協(xié)方差繪圖:

首先我們要根據(jù)均值和協(xié)方差獲取數(shù)據(jù)

?
1
2
3
4
mean,cov = [m,n],[(a,b),(c,d)]#指定均值和協(xié)方差
data = np.random.multivariate_normal(mean,cov,e)#根據(jù)均值和協(xié)方差獲取e個隨機數(shù)據(jù)
df = pd.dataframe(data,columns=["x","y"])#將數(shù)據(jù)指定為dataframe格式
df

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

然后繪制圖像

?
1
sns.jointplot(x="x",y="y",data=df) #繪制散點圖

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

sns.jointplot(x="x",y="y",data=df)可以繪制出x和y單變量的條形圖以及x與y多變量的散點圖。

7.在jointplot()函數(shù)中傳入kind=“hex”,能夠在數(shù)據(jù)量比較大時讓我們更清晰地看到數(shù)據(jù)的分布比重。

?
1
2
3
x,y = np.random.multivariate_normal(mean,cov,2000).t
with sns.axes_style("white"):
  sns.jointplot(x=x,y=y,kind="hex",color="c")

繪制出的圖像如下

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

8.sns.pairplot(df):繪制出各變量之間的散點圖與條形圖,且對角線均為條形圖。

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

在這里我們可以先使用df = sns.load_dataset("")將seaborn中原本帶有的數(shù)據(jù)讀入或用pandas讀取。

9.繪制回歸分析圖:這里可以用兩個函數(shù)regplot()lmplot(),用regplot()更好一些。

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

如果兩個變量不適合做回歸分析,我們可以傳入x_jitter()y_jitter()讓x軸或y軸的數(shù)據(jù)輕微抖動一些,得出較為準確的結(jié)果。

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

10.sns.stripplot(x="",y="",data=df,jitter=bool):繪制一個特征變量中的多個變量與另一變量關(guān)系的散點圖,jitter控制數(shù)據(jù)是否抖動。

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

11.sns.swarmplot(x="",y="",hue="",data=df):繪制頁狀散點圖,hue指定對數(shù)據(jù)的分類,由于在大量數(shù)據(jù)下,上面的散點圖會影響到我們對數(shù)據(jù)的觀察,這種圖能夠更清晰地觀察到數(shù)據(jù)分布。

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

12.sns.boxplot(x="",y="",hue="",data=df,orient="h"):繪制盒形圖,hue同樣指定對數(shù)據(jù)的分類。在統(tǒng)計學中有四分位數(shù)的概念,第一個四分位記做q1,第二個四分位數(shù)記做q2,第三個四分位數(shù)記做q3,q3-q1得到的結(jié)果q叫做四分位距,如果一個數(shù)n,n的范圍是n<q1-1.5q或n>q3+1.5q,則稱n為離群點,也就是不符合數(shù)據(jù)規(guī)范的點,利用盒形圖可以很清晰地觀察到離群點。如果傳入orient則畫出的盒形圖是橫向的。

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

13.sns.violinplot(x="",y="",data=df,hue="",split=bool):繪制小提琴圖,split表示是否將兩類數(shù)據(jù)分開繪制,如果為true,則不分開繪制,默認為false。

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

14.還可以將頁狀散點圖和小提琴圖在一起繪制,只需將兩個繪圖命令

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

inner="none"表示去除小提琴圖內(nèi)部的形狀。

15.sns.barplot(x="",y="",hue="",data=df):按hue的數(shù)據(jù)分類繪制條形圖。

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

16.sns.pointplot(x="",y="",hue="",data=df):繪制點圖,點圖可以更好的描述數(shù)據(jù)的變化差異。

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

17.我們還可以傳入其他參數(shù):

?
1
2
3
sns.pointplot(x="class",y="survived",hue="sex",data=titanic,
       palette={"male":"#02ff96","female":"#0980e6"},#指定曲線的顏色
       markers=["s","d"],linestyles=["-","-."])#指定曲線的點型和線型

繪制出的圖像如下

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

18.sns.factorplot(x="", y="", hue="", data=df):繪制多層面板分類圖。

?
1
sns.factorplot(x="day",y="total_bill",hue="smoker",data=tips)

繪制的圖像如下

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

19.sns.factorplot(x="",y="",hue="",data=df,kind=""):kind中指定要畫圖的類型。

?
1
sns.factorplot(x="day",y="total_bill",hue="smoker",data=tips,kind="bar")

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

?
1
sns.factorplot(x="day",y="total_bill",hue="smoker",col="time",data=tips,kind="swarm")

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

?
1
sns.factorplot(x="time",y="total_bill",hue="smoker",col="day",data=tips,kind="box",size=5,aspect=0.8) #aspect指定橫縱比

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

20.sns.factorplot()的參數(shù):

  • x,y,hue 數(shù)據(jù)集變量 變量名。
  • date 數(shù)據(jù)集 數(shù)據(jù)集名。
  • row,col 更多分類變量進行平鋪顯示 變量名。
  • col_wrap 每行的最高平鋪數(shù) 整數(shù)。
  • estimator 在每個分類中進行矢量到標量的映射 矢量。
  • ci 置信區(qū)間 浮點數(shù)或none。
  • n_boot 計算置信區(qū)間時使用的引導迭代次數(shù) 整數(shù)。
  • units 采樣單元的標識符,用于執(zhí)行多級引導和重復測量設(shè)計 數(shù)據(jù)變量或向量數(shù)據(jù)。
  • order, hue_order 對應排序列表 字符串列表。
  • row_order, col_order 對應排序列表 字符串列表。
  • kind : 可選:point 默認, bar 柱形圖, count 頻次, box 箱體, violin 提琴, strip 散點,swarm 分散點 size 每個面的高度(英寸) 標量 aspect 縱橫比 標量 orient 方向 "v"/"h" color 顏色 matplotlib顏色 palette 調(diào)色板 seaborn顏色色板或字典 legend hue的信息面板 true/false legend_out 是否擴展圖形,并將信息框繪制在中心右邊 true/false share{x,y} 共享軸線 true/false。

21.sns.facetgrid():這是一個很重要的繪圖函數(shù)。

?
1
2
g = sns.facetgrid(tips,col="time")
g.map(plt.hist,"tip")

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

?
1
2
3
g = sns.facetgrid(tips,col="sex",hue="smoker",size=5,aspect=1)
g.map(plt.scatter,"total_bill","tip",alpha=0.3,s=100)#alpha指定點的透明度,s指定點的大小
g.add_legend()#添加圖例

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

?
1
2
g = sns.facetgrid(tips,col="day",size=4,aspect=0.8)
g.map(sns.barplot,"sex","total_bill")

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

22.sns.pairgrid():將各變量間的關(guān)系成對繪制。

?
1
2
3
iris = sns.load_dataset("iris")
g = sns.pairgrid(iris)
g.map(plt.scatter)

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

23.g.map_diag()g.map_offdiag():繪制對角線和非對角線的圖形

?
1
2
3
g = sns.pairgrid(iris)
g.map_diag(plt.hist)  #指定對角線繪圖類型
g.map_offdiag(plt.scatter)  #指定非對角線繪圖類型

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

?
1
2
3
4
g = sns.pairgrid(iris, hue="species")
g.map_diag(plt.hist)
g.map_offdiag(plt.scatter)
g.add_legend()

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

?
1
2
g = sns.pairgrid(iris, vars=["sepal_length", "sepal_width"], hue="species",size=3)
g.map(plt.scatter)

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

?
1
2
3
g = sns.pairgrid(tips, hue="size", palette="gnbu_d")
g.map(plt.scatter, s=50, edgecolor="white")
g.add_legend()

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

24.sns.heatmap():繪制熱度圖,熱度圖可以很清楚看到數(shù)據(jù)的變化情況以及變化過程中的最大值和最小值。

?
1
2
3
uniform_data = np.random.rand(3, 3)
print (uniform_data)
heatmap = sns.heatmap(uniform_data)

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

25.向heatmap()中傳入?yún)?shù)vmin=vmax=

?
1
2
ax = sns.heatmap(uniform_data,vmin=0.2,vmax=0.5)
#超過最大值都是最大值的顏色,小于最小值都是最小值的顏色

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

26.

?
1
2
3
normal_data = np.random.randn(3, 3)
print (normal_data)
ax = sns.heatmap(normal_data, center=0#center指定右側(cè)圖例的中心值

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

27.

?
1
2
3
4
flights = sns.load_dataset("flights")
flights = flights.pivot("month", "year", "passengers")
ax = sns.heatmap(flights, annot=true,fmt="d",linewidth=0.5
#annot指定是否顯示數(shù)據(jù),fmt指定數(shù)據(jù)的顯示格式,linewidth指定數(shù)據(jù)格子間的距離

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

28.

?
1
2
ax = sns.heatmap(flights, cmap="ylgnbu",cbar=true)
#cmap指定圖形顏色,cbar表示是否繪制右側(cè)圖例。

Python數(shù)據(jù)可視化庫seaborn的使用總結(jié)

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:https://segmentfault.com/a/1190000017891341

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 欧美日本韩国一区二区 | 国产黄色一级片视频 | 精品成人免费一区二区在线播放 | 三区在线视频 | 国产一区影院 | 这里只有精品国产 | 午夜精品久久久久 | 国产亚洲精品久久久久久无几年桃 | 蜜桃传媒一区二区 | 久久99国产精一区二区三区 | 99这里只有精品 | 免费国产网站 | 国产一级久久久久 | 欧美视频一二三区 | 亚洲精品国精品久久99热 | 亚洲国产精品一区 | 91精品国产综合久久婷婷香蕉 | 中国大陆高清aⅴ毛片 | 欧美一级裸体视频 | 成人免费毛片嘿嘿连载视频 | 国内精品久久久久久中文字幕 | 午夜精品视频 | 久久久一区二区 | 成人性生交大片免费网站 | 欧美日韩在线电影 | 欧美日韩一级视频 | 日本不卡免费新一二三区 | 在线中文视频 | 欧美精品一区二区三区四区五区 | 亚洲 欧美 日韩在线 | 黄色片视频免费 | 日韩欧美国产一区二区 | 亚洲精品片 | 午夜电影网址 | 激情五月婷婷综合 | 欧美精品一区二区三区在线 | 一级二级黄色大片 | 91尤物网站网红尤物福利 | 成人中文字幕在线观看 | 中文在线一区二区 | 免费在线看污网站 |