数据可视化

#引入约定
import matplotlib.pyplot as plt

#matplotlib 图像保存在figure对象里
#创建新的figure
fig = plt.figure()
#其中figsize用于确保图片保存时的纵横比

#绘图需要创建一个或多个 subplot
axi = fig.add_subplot(2, 2, 1)
axi = fig.add_subplot(2, 2, 2)
axi = fig.add_subplot(2, 2, 3)
#代码意思图像是2*2 大小,选中的是第几个编号的subplot

在这里插入图片描述

plt.plot(randn(50).cumsum(), 'k--')
#其中 k-- 是先行选择,绘制黑色虚线图
text.groupby(['Sex','Survived'])['Survived'].count().unstack().plot(kind='bar',stacked='True')
plt.title('survived_count')
plt.ylabel('count')

在这里插入图片描述

# 排序前绘折线图
fare_sur1 = text.groupby(['Fare'])['Survived'].value_counts()
fare_sur1
fig = plt.figure(figsize=(20, 18))
fare_sur1.plot(grid=True)
plt.legend()
plt.show()
# 1表示生存,0表示死亡
pclass_sur = text.groupby(['Pclass'])['Survived'].value_counts()
pclass_sur

import seaborn as sns
sns.countplot(x="Pclass", hue="Survived", data=text)

在这里插入图片描述

text.Age[text.Pclass == 1].plot(kind='kde')
text.Age[text.Pclass == 2].plot(kind='kde')
text.Age[text.Pclass == 3].plot(kind='kde')
plt.xlabel("age")
plt.legend((1,2,3),loc="best")

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值