调整图边缘与 x 轴之间的间距
如何调整 x 轴和绘图窗口边缘之间的间距?我的 x 轴标签是垂直方向的,它们超出了 Matplotlib 绘制的窗口的边缘。
这是一些示例代码:
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()
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.
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如保罗所说,你正在使用数字。您可以使用 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: