Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何防止x轴标签从条形图底部被切断?_Python_Python 3.x_Matplotlib - Fatal编程技术网

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

Python 如何防止x轴标签从条形图底部被切断?,python,python-3.x,matplotlib,Python,Python 3.x,Matplotlib,这是我的密码: fig = plt.figure() plt.figure(figsize=(15, 6)) plt.bar(x_labels, y_labels, width=0.9) plt.xticks(rotation=90) 这将生成以下图表: 正如你所看到的,标签的底部不断被切断。我知道有一种解决方案是使用plt.savefig('rest.png',bbox_inches='tight'),但是如果不在savefig()中使用该参数,我如何适应这一切呢?如果不使用plt.save

这是我的密码:

fig = plt.figure()
plt.figure(figsize=(15, 6))
plt.bar(x_labels, y_labels, width=0.9)
plt.xticks(rotation=90)
这将生成以下图表:


正如你所看到的,标签的底部不断被切断。我知道有一种解决方案是使用
plt.savefig('rest.png',bbox_inches='tight')
,但是如果不在
savefig()中使用该参数,我如何适应这一切呢?如果不使用
plt.savefig()
,如何实现
bbox\u inches='tight'
的效果?还可以做些什么来适应这一切

试着给x轴一点缓冲

fig.subplots_adjust(bottom=0.6)

您可以尝试
plt.tight\u layout()
。如果这仍然不能给出所需的结果,您可以使用
plt.subplot\u adjust(bottom=0.3)
(根据需要调整
bottom
)。它们对最终图形都没有任何影响。当您说没有影响时,您是否仍然使用
bbox\u inches='tight'保存绘图?
不。如果我这样保存它,我不必使用这些方法(无论是
tight\u layout()
还是
subplot\u adjust()
)。不过,我正在保存图像。非常好。很高兴你被分类了!我试过这个,但似乎完全没有效果。我添加了很多代码行,最终没有对最终的图形进行任何更改。