Python学习笔记-绘图

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%%表示小数有2位,整数有1位的浮点数

labels自动对应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')


你可能感兴趣的:(Python学习笔记-绘图)