溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Python?Pandas工具繪制數(shù)據(jù)圖怎么實(shí)現(xiàn)

發(fā)布時(shí)間:2021-12-01 11:06:03 來(lái)源:億速云 閱讀:159 作者:小新 欄目:開(kāi)發(fā)技術(shù)

這篇文章主要為大家展示了“Python Pandas工具繪制數(shù)據(jù)圖怎么實(shí)現(xiàn)”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“Python Pandas工具繪制數(shù)據(jù)圖怎么實(shí)現(xiàn)”這篇文章吧。

背景介紹

Pandas的DataFrame和Series在Matplotlib基礎(chǔ)上封裝了一個(gè)簡(jiǎn)易的繪圖函數(shù),使得數(shù)據(jù)處理過(guò)程中方便可視化查看結(jié)果。

折線圖

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
data=np.random.randn(5,2)*10
df=pd.DataFrame(np.abs(data),index=[1,2,3,4,5],columns=[1,2])
df.plot()
plt.show()

Python?Pandas工具繪制數(shù)據(jù)圖怎么實(shí)現(xiàn)

條形圖

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
data=np.random.randn(5,2)*10
df=pd.DataFrame(np.abs(data),index=[1,2,3,4,5],columns=[1,2])
df.plot(kind='bar')
plt.show()

Python?Pandas工具繪制數(shù)據(jù)圖怎么實(shí)現(xiàn)

水平條形圖

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
data=np.random.randn(5,2)*10
df=pd.DataFrame(np.abs(data),index=[1,2,3,4,5],columns=[1,2])
df.plot(kind='barh')
plt.show()

Python?Pandas工具繪制數(shù)據(jù)圖怎么實(shí)現(xiàn)

堆積圖

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
data=np.random.randn(5,2)*10
df=pd.DataFrame(np.abs(data),index=[1,2,3,4,5],columns=[1,2])
df.plot(kind='bar',stacked=True)
plt.show()

Python?Pandas工具繪制數(shù)據(jù)圖怎么實(shí)現(xiàn)

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
data=np.random.randn(5,2)*10
df=pd.DataFrame(np.abs(data),index=[1,2,3,4,5],columns=[1,2])
df.plot(kind='barh',stacked=True)
plt.show()

Python?Pandas工具繪制數(shù)據(jù)圖怎么實(shí)現(xiàn)

散點(diǎn)圖

數(shù)據(jù)通常是一些點(diǎn)的集合

常用來(lái)繪制各種相關(guān)性,適合研究不同變量間的關(guān)系

  • x:x坐標(biāo)位置

  • y:y坐標(biāo)位置

  • s:散點(diǎn)的大小

  • c:散點(diǎn)顏色

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
data=np.random.randn(5,2)*10
df=pd.DataFrame(np.abs(data),index=[1,2,3,4,5],columns=['A','B'])
df.plot(kind='scatter',x='A',y='B',s=df.A*100,c='red')
plt.show()

Python?Pandas工具繪制數(shù)據(jù)圖怎么實(shí)現(xiàn)

餅圖

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df=pd.Series(3*np.random.rand(4),index=['a','b','c','d'])
df.plot.pie(figsize=(6,6))
plt.show()

Python?Pandas工具繪制數(shù)據(jù)圖怎么實(shí)現(xiàn)

蜂巢圖

體現(xiàn)數(shù)據(jù)出現(xiàn)的次數(shù)

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df=pd.DataFrame(np.random.randn(1000,2),columns=['a','b'])
df.plot.hexbin(x='a',y='b',sharex=False,gridsize=30)
plt.show()

Python?Pandas工具繪制數(shù)據(jù)圖怎么實(shí)現(xiàn)

箱線圖

基于最小值、上四分位、中位數(shù)、下四分位和最大值5個(gè)數(shù)值特征展示數(shù)據(jù)分布的標(biāo)準(zhǔn)方式,可以看出數(shù)據(jù)是否具有對(duì)稱性,適用于展示一組數(shù)據(jù)的分布情況

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df=pd.DataFrame(np.random.randn(1000,2),columns=['a','b'])
df.plot(y=df.columns,kind='box',vert=False)
plt.show()

Python?Pandas工具繪制數(shù)據(jù)圖怎么實(shí)現(xiàn)

繪制子圖

subplots:默認(rèn)False 若每列繪制子圖就為True

layout:子圖布局

figsize:畫(huà)布大小

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df=pd.DataFrame(np.random.randn(5,2),columns=['a','b'])
df.plot(subplots=True,layout=(2,3),figsize=(10,10),kind='bar')
plt.show()

Python?Pandas工具繪制數(shù)據(jù)圖怎么實(shí)現(xiàn)

以上是“Python Pandas工具繪制數(shù)據(jù)圖怎么實(shí)現(xiàn)”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI