简体   繁体   English

Python / Matplotlib - 调整绘图边缘和x轴之间的间距

[英]Python/Matplotlib - Adjusting the spacing between the edge of the plot and the x-axis

How can I adjust the amount of space between the x-axis and the edge of the plot window? 如何调整x轴和绘图窗口边缘之间的间距? My x-axis labels are oriented vertically and they are running off of the edge of the window that Matplotlib draws. 我的x轴标签垂直定向,它们正在运行Matplotlib绘制的窗口边缘。

Here's some example 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')
plt.show()

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 . 您可以使用gcf()获取当前数字的引用,然后根据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()

这是FAQ中的一个解决方案,题为移动轴的边缘以便为刻度标签腾出空间

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

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