python可視化數(shù)據(jù)分析圖的案例-創(chuàng)新互聯(lián)

創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務(wù)器提供商,新人活動買多久送多久,劃算不套路!

創(chuàng)新互聯(lián)公司從2013年開始,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目成都做網(wǎng)站、網(wǎng)站設(shè)計網(wǎng)站策劃,項目實(shí)施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元獻(xiàn)縣做網(wǎng)站,已為上家服務(wù),為獻(xiàn)縣各地企業(yè)和個人服務(wù),聯(lián)系電話:028-86922220

小編給大家分享一下python可視化數(shù)據(jù)分析圖的案例,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!

python數(shù)據(jù)分析常用圖大集合:包含折線圖、直方圖、垂直條形圖、水平條形圖、餅圖、箱線圖、熱力圖、散點(diǎn)圖、蜘蛛圖、二元變量分布、面積圖、六邊形圖等12種常用可視化數(shù)據(jù)分析圖,后期還會不斷的收集整理,請關(guān)注更新!

以下默認(rèn)所有的操作都先導(dǎo)入了numpypandas、matplotlib、seaborn

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

一、折線圖

折線圖可以用來表示數(shù)據(jù)隨著時間變化的趨勢

x = [2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019]
y = [5, 3, 6, 20, 17, 16, 19, 30, 32, 35]

Matplotlib

plt.plot(x, y)
plt.show()

python可視化數(shù)據(jù)分析圖的案例

Seaborn

df = pd.DataFrame({'x': x, 'y': y})
sns.lineplot(x="x", y="y", data=df)
plt.show()

python可視化數(shù)據(jù)分析圖的案例

二、直方圖

直方圖是比較常見的視圖,它是把橫坐標(biāo)等分成了一定數(shù)量的小區(qū)間,然后在每個小區(qū)間內(nèi)用矩形條(bars)展示該區(qū)間的數(shù)值

a = np.random.randn(100)
s = pd.Series(a)

Matplotlib

plt.hist(s)
plt.show()

python可視化數(shù)據(jù)分析圖的案例

Seaborn

sns.distplot(s, kde=False)
plt.show()
sns.distplot(s, kde=True)
plt.show()

python可視化數(shù)據(jù)分析圖的案例

python可視化數(shù)據(jù)分析圖的案例

三、垂直條形圖

條形圖可以幫我們查看類別的特征。在條形圖中,長條形的長度表示類別的頻數(shù),寬度表示類別。

x = ['Cat1', 'Cat2', 'Cat3', 'Cat4', 'Cat5']
y = [5, 4, 8, 12, 7]

Matplotlib

plt.bar(x, y)
plt.show()

python可視化數(shù)據(jù)分析圖的案例

Seaborn

plt.show()

python可視化數(shù)據(jù)分析圖的案例

四、水平條形圖

x = ['Cat1', 'Cat2', 'Cat3', 'Cat4', 'Cat5']
y = [5, 4, 8, 12, 7]
plt.barh(x, y)
plt.show()

python可視化數(shù)據(jù)分析圖的案例

五、餅圖

nums = [25, 37, 33, 37, 6]
labels = ['High-school','Bachelor','Master','Ph.d', 'Others']
plt.pie(x = nums, labels=labels)
plt.show()

python可視化數(shù)據(jù)分析圖的案例

六、箱線圖

箱線圖由五個數(shù)值點(diǎn)組成:大值 (max)、最小值 (min)、中位數(shù) (median) 和上下四分位數(shù) (Q3, Q1)。

可以幫我們分析出數(shù)據(jù)的差異性、離散程度和異常值等。

Matplotlib

# 生成0-1之間的10*4維度數(shù)據(jù)
data=np.random.normal(size=(10,4)) 
lables = ['A','B','C','D']
# 用Matplotlib畫箱線圖
plt.boxplot(data,labels=lables)
plt.show()

python可視化數(shù)據(jù)分析圖的案例

Seaborn

# 用Seaborn畫箱線圖
df = pd.DataFrame(data, columns=lables)
sns.boxplot(data=df)
plt.show()

python可視化數(shù)據(jù)分析圖的案例

七、熱力圖

力圖,英文叫 heat map,是一種矩陣表示方法,其中矩陣中的元素值用顏色來代表,不同的顏色代表不同大小的值。通過顏色就能直觀地知道某個位置上數(shù)值的大小。

flights = sns.load_dataset("flights")
data=flights.pivot('year','month','passengers')
sns.heatmap(data)
plt.show()

python可視化數(shù)據(jù)分析圖的案例

通過 seaborn 的 heatmap 函數(shù),我們可以觀察到不同年份,不同月份的乘客數(shù)量變化情況,其中顏色越淺的代表乘客數(shù)量越多

八、散點(diǎn)圖

散點(diǎn)圖的英文叫做 scatter plot,它將兩個變量的值顯示在二維坐標(biāo)中,非常適合展示兩個變量之間的關(guān)系。

N = 1000
x = np.random.randn(N)
y = np.random.randn(N)

Matplotlib

plt.scatter(x, y,marker='x')
plt.show()

python可視化數(shù)據(jù)分析圖的案例

Seaborn

df = pd.DataFrame({'x': x, 'y': y})
sns.jointplot(x="x", y="y", data=df, kind='scatter');
plt.show()

python可視化數(shù)據(jù)分析圖的案例

九、蜘蛛圖

蜘蛛圖是一種顯示一對多關(guān)系的方法,使一個變量相對于另一個變量的顯著性是清晰可見

labels=np.array([u"推進(jìn)","KDA",u"生存",u"團(tuán)戰(zhàn)",u"發(fā)育",u"輸出"])
stats=[83, 61, 95, 67, 76, 88]
# 畫圖數(shù)據(jù)準(zhǔn)備,角度、狀態(tài)值
angles=np.linspace(0, 2*np.pi, len(labels), endpoint=False)
stats=np.concatenate((stats,[stats[0]]))
angles=np.concatenate((angles,[angles[0]]))
# 用Matplotlib畫蜘蛛圖
fig = plt.figure()
ax = fig.add_subplot(111, polar=True)   
ax.plot(angles, stats, 'o-', linewidth=2)
ax.fill(angles, stats, alpha=0.25)
# 設(shè)置中文字體
font = FontProperties(fname=r"/System/Library/Fonts/PingFang.ttc", size=14)  
ax.set_thetagrids(angles * 180/np.pi, labels, FontProperties=font)
plt.show()

python可視化數(shù)據(jù)分析圖的案例

十、二元變量分布

二元變量分布可以看兩個變量之間的關(guān)系

tips = sns.load_dataset("tips")
tips.head(10)
#散點(diǎn)圖
sns.jointplot(x="total_bill", y="tip", data=tips, kind='scatter')
#核密度圖
sns.jointplot(x="total_bill", y="tip", data=tips, kind='kde')
#Hexbin圖
sns.jointplot(x="total_bill", y="tip", data=tips, kind='hex')
plt.show()

python可視化數(shù)據(jù)分析圖的案例

python可視化數(shù)據(jù)分析圖的案例

python可視化數(shù)據(jù)分析圖的案例

十一、面積圖

面積圖又稱區(qū)域圖,強(qiáng)調(diào)數(shù)量隨時間而變化的程度,也可用于引起人們對總值趨勢的注意。

堆積面積圖還可以顯示部分與整體的關(guān)系。折線圖和面積圖都可以用來幫助我們對趨勢進(jìn)行分析,當(dāng)數(shù)據(jù)集有合計關(guān)系或者你想要展示局部與整體關(guān)系的時候,使用面積圖為更好的選擇。

df = pd.DataFrame(
np.random.rand(10, 4), 
columns=['a', 'b', 'c', 'd'])
# 堆面積圖
df.plot.area()
# 面積圖
df.plot.area(stacked=False)

python可視化數(shù)據(jù)分析圖的案例

十二、六邊形圖

六邊形圖將空間中的點(diǎn)聚合成六邊形,然后根據(jù)六邊形內(nèi)部的值為這些六邊形上色。

df = pd.DataFrame(
np.random.randn(1000, 2), 
columns=['a', 'b'])
df['b'] = df['b'] + np.arange(1000)
# 關(guān)鍵字參數(shù)gridsize;它控制x方向上的六邊形數(shù)量,默認(rèn)為100,較大的gridsize意味著更多,更小的bin
df.plot.hexbin(x='a', y='b', gridsize=25)

python可視化數(shù)據(jù)分析圖的案例

看完了這篇文章,相信你對python可視化數(shù)據(jù)分析圖的案例有了一定的了解,想了解更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道,感謝各位的閱讀!

網(wǎng)站欄目:python可視化數(shù)據(jù)分析圖的案例-創(chuàng)新互聯(lián)
URL鏈接:http://www.muchs.cn/article0/cdecoo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動網(wǎng)站建設(shè)、云服務(wù)器、用戶體驗(yàn)、企業(yè)網(wǎng)站制作、網(wǎng)站策劃網(wǎng)站設(shè)計

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)