import pandas as pd
# Create a random time series with values over 100 days
# starting from 1st March.
N = 100
dates = pd.date_range(start='2015-03-01', periods=N, freq='D')
ts = pd.DataFrame({'date': dates,
'values': np.random.randn(N)}).set_index('date')
# Create the plot and adjust x/y limits. The new x-axis
# ranges from mid-February till 1st July.
ax = ts.plot()
ax.set_xlim(pd.Timestamp('2015-02-15'), pd.Timestamp('2015-07-01'))
ax.set_ylim(-5, 5)
如果我使用
pd.Timestamp
值设置x轴限制,它对我(pandas为0.16.2)有效。示例:
结果:
请注意,如果在同一图中绘制多个时间序列,请确保在最后一个
ts.plot()
命令之后设置xlim/ylim,否则pandas将自动重置限制以匹配内容。相关问题 更多 >
编程相关推荐