use*_*531 16 python matplotlib bar-chart seaborn
我使用seaborn绘制分组条形图,如https://seaborn.pydata.org/examples/factorplot_bars.html
给我:https: //seaborn.pydata.org/_images/factorplot_bars.png
传说中有一个标题(性别),我想删除.
我怎么能实现这一目标?
ber*_*nie 11
这可能是一个hacky解决方案,但它的工作原理:如果你告诉Seaborn在绘图时将其关闭,然后将其添加回来,它就没有传说标题:
g = sns.factorplot(x='Age Group',y='ED',hue='Became Member',col='Coverage Type',
col_wrap=3,data=gdf,kind='bar',ci=None,legend=False,palette='muted')
# ^^^^^^^^^^^^
plt.suptitle('ED Visit Rate per 1,000 Members per Year',size=16)
plt.legend(loc='best')
plt.subplots_adjust(top=.925)
plt.show()
Run Code Online (Sandbox Code Playgroud)
示例结果:
dil*_*lon 10
一种不太常见的方法是使用matplotlib的面向对象的接口.通过获得轴的控制,可以更容易地定制绘图.
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="whitegrid")
# Load the example Titanic dataset
titanic = sns.load_dataset("titanic")
# Draw a nested barplot to show survival for class and sex
fig, ax = plt.subplots()
g = sns.factorplot(x="class", y="survived", hue="sex", data=titanic,
size=6, kind="bar", palette="muted", ax=ax)
sns.despine(ax=ax, left=True)
ax.set_ylabel("survival probability")
l = ax.legend()
l.set_title('Whatever you want')
fig.show()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20102 次 |
| 最近记录: |