从OP看到实际数据后,所有值都在同一日期/时间。因此matplotlib自动将x轴缩小。你仍然可以手动设置
datetime对象的x轴限制
如果我在matplotlib v1.3.1上做了类似的事情:
import datetimeimport matplotlib.pyplot as pltx = [datetime.date(2014, 1, 29), datetime.date(2014, 1, 29), datetime.date(2014, 1, 29)] y = [2, 4, 1]fig, ax = plt.subplots()ax.plot_date(x, y, markerfacecolor='CornflowerBlue', markeredgecolor='white')fig.autofmt_xdate()ax.set_xlim([datetime.date(2014, 1, 26), datetime.date(2014, 2, 1)])ax.set_ylim([0, 5])
我得到:
并且轴限制与我指定的日期匹配。



