osc*_*876 2 python datetime matplotlib pandas
如何在特定日期向此图表添加垂直线标记?Week end是日期列。
fig, ax = plt.subplots(figsize=(20,9))
thirteen.plot.line(x='Week end', y='OFF', color='crimson', ax=ax)
thirteen.plot.line(x='Week end', y='ON', color='blue', ax=ax)
ax.set_ylim(bottom=0)
plt.show()
Run Code Online (Sandbox Code Playgroud)
首先确保日期列Week end已转换to_datetime。
# convert to datetime date type
thirteen['Week end'] = pd.to_datetime(thirteen['Week end'])
fig, ax = plt.subplots(figsize=(20, 9))
thirteen.plot.line(x='Week end', y='OFF', color='crimson', ax=ax)
thirteen.plot.line(x='Week end', y='ON', color='blue', ax=ax)
# plot vertical line at one date
ax.axvline(x='2013-07-01', color='k')
# plot vertical lines at two dates from y=0 to y=250
ax.vlines(x=['2013-11-01', '2014-04-15'], ymin=0, ymax=250, color='k', ls='--')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5083 次 |
| 最近记录: |