Python學(xué)習(xí)筆記-繪圖

1.使用matplotlib畫餅狀圖(pie)

import pandas as pd

import matplotlib.pyplot as plt

%matplotlib inline

Survived_count =titanic_newdf.groupby('Survived')['Survived'].count()

print Survived_count

------

Survived

0? ? 424

1? ? 290

Name: Survived, dtype: int64

--------

0為Non-survived,1為Survived:

plt.pie(Survived_count, labels=['Non-survived','Survived'], autopct='%2.1f%%')

#autopct,圓里面的文本格式,%2.1f%%表示小數(shù)有2位,整數(shù)有1位的浮點數(shù)

labels自動對應(yīng)Survived_count的第0和1行


2. 柱狀圖

surv_rate_bysex

-----

Sex

female? ? 0.754789

male? ? ? 0.205298

Name: Survived, dtype: float64

-----

surv_rate_bysex.plot(kind='bar',title='Sex vs Survived Rate')

plt.ylabel('Survived Rate')


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容