【发布时间】:2022-12-13 00:44:16
【问题描述】:
我正在绘制时间序列数据,这些数据将被分成训练和测试数据集。现在,我想在图中画一条垂直线,表示训练/测试数据拆分发生的位置。
split_point indicates where the data should be plotted.
df = pd.read_csv('https://raw.githubusercontent.com/selva86/datasets/master/a10.csv', parse_dates=['date'], index_col='date')
df
data_size=len(df)
split_point = data_size - data_size // 3
split_point
# Draw Plot
def plot_df(df, x, y, title="", xlabel='Date', ylabel='Value', dpi=100):
plt.figure(figsize=(16,5), dpi=dpi)
plt.plot(x, y, color='tab:red')
plt.gca().set(title=title, xlabel=xlabel, ylabel=ylabel)
plt.show()
plot_df(df, x=df.index, y=df.value, title='Monthly anti-diabetic drug sales in Australia from 1992 to 2008.')
如何将其添加到情节中?我尝试使用plt.axvline,但不知道如何从分割点转到日期。有任何想法吗?
plt.axvline(split_point)
【问题讨论】:
标签: python matplotlib time-series