pycharm做箱式图、散点图、饼图

本文详细介绍了如何使用Python的PyCharm IDE创建统计图表,包括箱式图用于展示数据分布,散点图用于表示两个变量之间的关系,以及饼图用于展示各部分占比。通过实例代码,读者可以轻松掌握这些图表的绘制方法。
摘要由CSDN通过智能技术生成
#导入Excel数据studentshuju.xls的代码:
import matplotlib.pyplot as plt
import pandas as pd
import xlrd
import seaborn as sns
df = pd.read_excel('C:\hadoop-2.8.4\studentshuju.xls')
print (df)


#做箱式图的代码:
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.boxplot(df['age'])
plt.show()


#做散点图的代码:
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
x=df['xuhao']
y=df['height']
z=df['weight']
ax.scatter(x,y,c='b',marker='s',s=30)
ax.scatter(x,z,c='y',marker='o',s=60)
plt.show()


#做饼图的代码:
var = df.groupby(['sex']).sum().stack()
t=var.unstack()
type(t)
x = t ['age']
label1 = t.index
plt.axis('equal')
plt.pie(x,labels=label1,autopct='%1.1f%%')
plt.show()


  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值