如何在matplotlib上添加一条垂直线? [英] how to ad a vertical line to matplotlib?

查看:1047
本文介绍了如何在matplotlib上添加一条垂直线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在x = '23:30:00'处显示一条垂直线.我也尝试过x = '23:30'.有什么想法吗?

I want to show a vertical line at x='23:30:00'. I have tried x = '23:30' as well. Any ideas?

df1 = df1.between_time('19:30','23:59')
df1['high'].plot(kind='line',figsize = (10,5))
plt.axvline(x='23:30:00', color = 'r')
plt.show()

推荐答案

您应该以日期时间格式传递您想要的行的点,而不是传递的字符串.简单地:

You should pass the point you want the line in datetime format instead of the string you pass. Simply:

#datetime format input
plt.axvline(x= datetime.datetime(2017, 9, 25,23,30), color = 'r')

在随机数据帧上的结果:

Result on a random dataframe:

这篇关于如何在matplotlib上添加一条垂直线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆