我有两个问题:
plt.figure(figsize=(40,20))
g = sns.catplot(x = 'Subject', y = 'EE Score',data = df , hue = 'Session',col='Grade',sharey = True,sharex = True,
hue_order=["2017-18", "2018-19", "2019-20"], kind="bar");
#plt.legend(bbox_to_anchor=(1, 1), loc=2)
g.set(ylim=(0, 100))
g.set_axis_labels("Subject", "EE Score")
ax = g.facet_axis(0,0)
for p in ax.patches:
ax.text(p.get_x() + 0.015,
p.get_height() * 1.02,
'{0:.1f}'.format(p.get_height()),
color='black', rotation='horizontal', size=12)
ax = g.facet_axis(0,1)
for p in ax.patches:
ax.text(p.get_x() + 0.015,
p.get_height() * 1.02,
'{0:.1f}'.format(p.get_height()),
color='black', rotation='horizontal', size=12)
ax = g.facet_axis(0,2)
for p in ax.patches:
ax.text(p.get_x() + 0.015,
p.get_height() * 1.02,
'{0:.1f}'.format(p.get_height()),
color='black', rotation='horizontal', size=12)
ax = g.facet_axis(0,3)
for p in ax.patches:
ax.text(p.get_x() + 0.015,
p.get_height() * 1.02,
'{0:.1f}'.format(p.get_height()),
color='black', rotation='horizontal', size=12)
#g.set_ylabel('')
plt.savefig('2.png', bbox_inches = 'tight')
和@johanc一样,我最初认为不可能从catplot()
中删除空类别。但是,Michael的评论提供了解决方案:sharex=False
。
color=
参数。
titanic = sns.load_dataset('titanic')
# remove one category
titanic.drop(titanic.loc[(titanic['class']=='First')&(titanic['who']=='child')].index, inplace=True)
g = sns.catplot(x="who", y="survived", col="class", data=titanic, kind="bar", ci=None, sharex=False)
这篇关于如何从CatPlot中删除空条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!