admin管理员组文章数量:1432643
I have following function to produce seaborn bar charts.
def create_bar_chart(data,
numeric_col,
category_col,
group_col=None,
x_min=0,
x_max=100,
fig_width_cm=12,
fig_heigth_cm=8):
fig, ax = plt.subplots(figsize=(cm*fig_width_cm, cm*fig_heigth_cm))
palette= {"Portfolio": "#00915A", "Benchmark": "#B3B3B3"}
if group_col is None:
group_col = category_col
sns.barplot(data, x=numeric_col, y=category_col, hue=group_col, legend=False, palette=palette, width=0.4)
sns.despine(offset=10, trim=True)
ax.set_xlim(x_min, x_max)
ax.yaxis.grid(False) # Hide the horizontal gridlines
ax.xaxis.grid(True) # Show the vertical gridlines
for container in ax.containers:
ax.bar_label(container, fmt='{:.2f}', fontsize=8)
return fig
I want the x-Axis to have a value range between e.g. 0-100 and also have vertical gridlines for this range. Therefore, I am using ax.set_xlim()
However, with the current setting the axis labels and vertical gridlines are determined by the maximum x value of the data... only the chart grid size is impacted by ax.set_xlim
... A screenshot to illustrate:
Do you know what I am missing? Thanks
本文标签: matplotlibPython Seabornsetxlimaxis labels do not appear on axisStack Overflow
版权声明:本文标题:matplotlib - Python Seaborn - set_xlim - axis labels do not appear on axis - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745566344a2663781.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论