简体   繁体   English

如何阻止 x 轴标签从条形图的底部被切断?

[英]How to stop the x-axis labels from getting cut off from the bottom of the bar graph?

Here's my code:这是我的代码:

fig = plt.figure()
plt.figure(figsize=(15, 6))
plt.bar(x_labels, y_labels, width=0.9)
plt.xticks(rotation=90)

This yields this graph:这产生了这张图: matplotlib 糟透了

As you can see, the bottoms of the labels keep getting cut off.如您所见,标签的底部不断被切断。 I know one solution is to use plt.savefig('rest.png', bbox_inches='tight') but how do I fit it all without using that argument in savefig() ?我知道一种解决方案是使用plt.savefig('rest.png', bbox_inches='tight')但是我如何在不使用savefig()中的参数的情况下适应它? How can I achieve that effect of bbox_inches='tight' without using plt.savefig() ?如何在不使用plt.savefig()的情况下实现bbox_inches='tight'效果? What else can be done to fit it all?还能做些什么来适应这一切?

尝试给 x 轴一点缓冲

fig.subplots_adjust(bottom=0.6)

The line that worked for me while I was working on long tick marks was:在我处理长刻度线时对我有用的是:

plt.tight_layout()
plt.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM