美文网首页
Python学习笔记-绘图

Python学习笔记-绘图

作者: 风媒花 | 来源:发表于2017-12-26 21:34 被阅读0次

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学习笔记-绘图

      本文链接:https://www.haomeiwen.com/subject/mdbegxtx.html