使用datetime值设置xlim

时间:2018-05-14 19:05:51

标签: pandas matplotlib python-3.6

我正在尝试修改图形graph,特别是我不喜欢在x轴上看左边和右边的空格,并希望它挤压以适应。

x轴的值是datetime对象。

xmin,xmax = plt.xlim()
print(xmax)
print(xmin)

返回

17707.15
16757.85

修改这些限制的正确方法是什么?我应该将正确的datetime对象转换为int并使用它设置xlim。或者matplotlib中是否有一个函数可以为我删除这些间隙(仅在x轴上)。

1 个答案:

答案 0 :(得分:0)

ax.autoscale(enable=True, axis='x', tight=True)

制作

enter image description here 来自https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.autoscale.html