Pandas中,画直方图Hist 的四种方法,以及其他绘图

Pandas中,画直方图Hist 的四种方法,以及其他绘图

 

Pandas中,画直方图Hist 的四种方法:

1、画直方图 sns.distplot(hist=True) 或者 df.plot(kind='hist') 或者 plt.hist() 或者 df.hist() :

 

  • # 方法一:

# 使用Pandas的画图函数:df.hist()
data_train['Age'].hist(bins=100)

 

  • # 方法二:

# 使用Pandas的画图函数:df.plot(kind='hist')
# 画柱状图使用:df.plot(kind='bar'), 画核密度图:df.plot(kind='kde')
data_train['Age'].plot(kind='hist',bins=100)

 

  • # 方法三:

# 使用seaborn的画图函数:sns.displot(hist=True)
sns.distplot(data_train.Age,hist=True,bins=100,kde=False)

 

  • # 方法四:

# 使用matplotlib的画图函数plt.hist()
plt.hist(data_train.Age,bins=100)

from matplotlib.pyplot import MultipleLocator

fig=plt.figure(figsize=(20,10))
# plt.subplot(1,2,1)
ax1=fig.add_subplot(1,2,1)


# 方法一:
# 使用Pandas的画图函数:df.hist()
data_train['Age'].hist(bins=100)


# 方法二:
# 使用Pandas的画图函数:df.plot(kind='hist')
# 画柱状图使用:df.plot(kind='bar'), 画核密度图:df.plot(kind='kde')
data_train['Age'].plot(kind='hist',bins=100)


# 方法三:
# 使用seaborn的画图函数:sns.displot(hist=True)
sns.distplot(data_train.Age,hist=True,bins=100,kde=False)


# 方法四:
# 使用matplotlib的画图函数plt.hist()
plt.hist(data_train.Age,bins=100)



ax1.set_xlabel("年龄")
ax1.set_ylabel("数量")
ax1.set_xlim(0,100)

# 设置坐标轴刻度的间隔为 5
locator=MultipleLocator(5)
ax1.xaxis.set_major_locator(locator)

plt.show()

ax2=fig.add_subplot(1,2,2)
sns.boxplot(y='Age',data=data_train,showfliers=False)
plt.show()

 方法一:                                                                                     方法二:

               

 

 方法三:                                                                                     方法四: 

                                

 

2、画核密度分布图 sns.distplot(kde=True) 或者 df.plot(kind='kde'):

 

3、画风琴图 sns.violinplot():

 

4、画统计图 sns.countplot():

 

5、画柱状图 sns.barplot() 或者 df.plot(kind='bar') 或者 plt.bar() 或者 df.bar() :

 

 

6、画饼图  df.plot(kind='pie') 或者 plt.pie() 或者 df.pie() :

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值