免费A级毛片无码专区网站-成人国产精品视频一区二区-啊 日出水了 用力乖乖在线-国产黑色丝袜在线观看下-天天操美女夜夜操美女-日韩网站在线观看中文字幕-AV高清hd片XXX国产-亚洲av中文字字幕乱码综合-搬开女人下面使劲插视频

python-繪圖與可視化( 三 )


python-繪圖與可視化

文章插圖
使用seaborn的優(yōu)點有:1.seaborn默認淺灰色背景與白色網(wǎng)格線的靈感來源于Matplotlib,卻比matplotlib的顏色更加柔和;2.seaborn把繪圖風格參數(shù)與數(shù)據(jù)參數(shù)分開設置 。seaborn有兩組函數(shù)對風格進行控制:axes_style()/set_style()函數(shù)和plotting_context()/set_context()函數(shù) 。axes_style()函數(shù)和plotting_context()函數(shù)返回參數(shù)字典,set_style()函數(shù)和set_context()函數(shù)設置Matplotlib 。
(1)使用set_style()函數(shù)具體通過cording查看效果:
import seaborn as snssns.set_style("ticks")sns.set_style("whitegrid")sinplot()plt.show()#seaborn 有5種預定義的主題:#darkgrid (灰色背景+白網(wǎng)格)#whitegrid(白色背景+黑網(wǎng)格)#dark (僅灰色背景)#white (僅白色背景)#ticks (坐標軸帶刻度)#默認的主題是darkgrid,修改主題可以使用set_style()函數(shù)
python-繪圖與可視化

文章插圖
(2)使用set_context()函數(shù)具體通過coding查看效果:
import seaborn as snssns.set_context("paper")sinplot()plt.show()#上下文(context)可以設置輸出圖片的大小尺寸(scale)#seaborn中預定義的上下文有4種:paper、notebook、talk和poster 。 默認使用notebook上下文
python-繪圖與可視化

文章插圖
(3)使用Seaborn“耍酷”然而seaborn 不僅能夠用來更改背景顏色,或者改變畫布大小,還有其他很多方面的用途,比如下面這個例子:
import seaborn as snssns.set()#通過加載sns自帶數(shù)據(jù)庫中的數(shù)據(jù)(具體數(shù)據(jù)可以不關心)flights_long = sns.load_dataset("flights")flights = flights_long.pivot("month","year","passengers")#使用每個單元格中的數(shù)據(jù)值繪制一個熱圖heatmapsns.heatmap(flights,annot=True,fmt="d",linewidths=.5)plt.show()
python-繪圖與可視化

文章插圖
4.描述性統(tǒng)計圖形概覽描述性統(tǒng)計是借助圖表或者總結性的數(shù)值來描述數(shù)據(jù)的統(tǒng)計手段 。數(shù)據(jù)挖掘工作的數(shù)據(jù)分析階段,我們可借助描述性統(tǒng)計來描述或總結數(shù)據(jù)的基本情況,一來可以梳理自己的思維,二來可以更好地向他人展示數(shù)據(jù)分析結果 。數(shù)值分析的過程中,我們往往要計算出數(shù)據(jù)的統(tǒng)計特征,用來做科學計算的Numpy和SciPy工具可以滿足我們的需求 。Matplotlib工具可用來繪制圖,滿足圖分析的需求 。
4.1制作數(shù)據(jù)數(shù)據(jù)是自己制作的,主要包括個人身高、體重及一年的借閱圖書量(之所以自己制作數(shù)據(jù)是因為不是每份真實的數(shù)據(jù)都可以進行接下來的分析,比如有些數(shù)據(jù)就不能繪制餅圖,另一個角度也說明,此處舉例的數(shù)據(jù)其實沒有實際意義,只是為了分析而舉例,但是不代表在具體的應用中這些分析不能發(fā)揮作用) 。另外,以下的數(shù)據(jù)顯示都是在Seaborn庫的作用下體現(xiàn)的效果 。
#案例分析(結合圖書情報學,比如借書量)from numpy import arrayfrom numpy.random import normaldef getData():    heights = []    weights = []    books = []    N =10000    for i in range(N):        while True:            #身高服從均值為172,標準差為6的正態(tài)分布            height = normal(172,6)            if 0<height:break        while True:            #體重由身高作為自變量的線性回歸模型產(chǎn)生,誤差服從標準正態(tài)分布            weight = (height-80)*0.7 + normal(0,1)            if 0 < weight:break        while True:            #借閱量服從均值為20,標準差為5的正態(tài)分布            number = normal(20,5)            if 0<= number and number<=50:                book = "E"if number <10 else("D"if number<15 else ("C"if number<20 else("B"if number<25 else "A")))            break        heights.append(height)        weights.append(weight)        books.append(book)        return array(heights),array(weights),array(books)    heights,weights,books =getData()

經(jīng)驗總結擴展閱讀