如何在 matplotlib 中绘制特定日期的垂直线
如何在特定日期向此图表添加垂直线标记? 周末
是日期列。
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()
How could I add a vertical line marker to this chart at a specific date? Week end
is the date column.
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先确保日期列
周末
已转换to_datetime
。然后使用
axvline
或vlines
:axvline
一次只能绘制一条垂直线,并且会自动填充整个y
范围vlines
可以绘制多条垂直线立即,但您必须指定y
边界First make sure the date column
Week end
has been convertedto_datetime
.Then use either
axvline
orvlines
:axvline
can only plot one vertical line at a time and will automatically fill the wholey
rangevlines
can plot multiple vertical lines at once, but you have to specify they
bounds