编辑边界以消除 matplotlib 中绘图中的空白 [英] Editing bounds to get rid of white-space within a plot in matplotlib
问题描述
![左:2000-2040 年的数据,右:2001-2039 年的数据][2]
![Left: Data from 2000-2040, Right: Data from 2001-2039][2]
有没有办法手动编辑我的绘图边界?当我的 x 轴数据从 2000 年运行到 2040 年时,matplotlib 会重新排列绘图,以便在绘图的左侧和右侧产生大量空白,如左图所示.但是,当我将 x 轴数据从 2001 更改为 2039 时,没有右图中的空格.我怀疑这是因为 matplotlib 如何自动排列刻度.问题是如何手动操作 x-ticks 以避免不必要的空白?有什么想法吗?
Is there a way I can manually edit the bounds of my plot? When my x axis data runs from 2000 to 2040 matplotlib rearranges the plot such that a lot of white-space is produced on both the left and right sides of the plot, as in the left picture. However when I change my x axis data from 2001 to 2039 there is no whitespace as in the right picture. I suspect this happens because of how matplotlib automatically arranges the ticks. The question is how can the x-ticks be manipulated manually to avoid unnecessary whitespace? Any ideas?
推荐答案
您可以使用名为 xlim
、ylim
的各种 pyplot 函数(设置轴的限制)、xticks
、yticks
(设置刻度位置)等.阅读 文档.
You can use the various pyplot functions called xlim
, ylim
(to set the limits of the axes), xticks
, yticks
(to set the tick positions) etc. Read the documentation.
这篇关于编辑边界以消除 matplotlib 中绘图中的空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!