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)
matplotlib中subplot# ⽅法⼆:
# 使⽤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、画统计图 untplot():
5、画柱状图 sns.barplot() 或者 df.plot(kind='bar') 或者 plt.bar() 或者 df.bar() :
6、画饼图 df.plot(kind='pie') 或者 plt.pie() 或者 df.pie() :
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论