Python/Matplotlib-调整绘图边缘与x轴之间的间距 [英] Python/Matplotlib - Adjusting the spacing between the edge of the plot and the x-axis

查看:651
本文介绍了Python/Matplotlib-调整绘图边缘与x轴之间的间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何调整X轴和绘图窗口边缘之间的间距?我的x轴标签是垂直方向的,它们从Matplotlib绘制的窗口边缘移开.

How can I adjust the amount of space between the x-axis and the edge of the plot window? My x-axis labels are oriented vertically and they are running off of the edge of the window that Matplotlib draws.

这是一些示例代码:

import matplotlib.pyplot as plt
x=[1,2,3,4,5]
y=[1,2,3,4,5]
plt.plot(x,y)
plt.xticks(rotation='vertical')
plt.show()

推荐答案

正如Paul所说,您使用的是数字.您可以使用 gcf() 获取对当前图形的引用,然后根据

As Paul said, you are using figures. You can get a reference to the current figure with gcf() and then set the spacing as per the FAQ. I've added two lines to your code:

import matplotlib.pyplot as plt
x=[1,2,3,4,5]
y=[1,2,3,4,5]
plt.plot(x,y)
plt.xticks(rotation='vertical')

fig = plt.gcf()
fig.subplots_adjust(bottom=0.2)

plt.show()

这篇关于Python/Matplotlib-调整绘图边缘与x轴之间的间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆