【问题标题】:Add vertical line to pandas df.plot of timeseries将垂直线添加到时间序列的 pandas df.plot
【发布时间】:2020-05-15 00:09:36
【问题描述】:

我有一个时间序列图,我想在event time 处添加一条垂直线。如果我使用此代码:

event_time = pd.to_datetime('10/12/2016 06:21:00')
ax = df_stats_t.plot(x = 't', y='t_TI_var_pwr', linestyle='none',...
color = 'black', marker = 'o')
ax1 = ax.twinx()
ax1.axvline(event_time, color='red', linestyle='-')
df_stats_t.plot(x='t',y='t_TI_var_ws',ax=ax1, linestyle='none', ...
color = 'green', marker = 'o')

它采用从event_time 开始的时间序列子集,并且不会产生垂直线。

如果我将ax1.axvline(event_time, color='red', linestyle='-') 移动到底部,我会得到我想要的图,但垂直线仍然缺失。

    event_time = pd.to_datetime('10/12/2016 06:21:00')
    ax = df_stats_t.plot(x = 't', y='t_TI_var_pwr', linestyle='none',... 
    color = 'black', marker = 'o')
    ax1 = ax.twinx()
    df_stats_t.plot(x='t',y='t_TI_var_ws',ax=ax1, linestyle='none',... 
    color = 'green', marker = 'o')
    ax1.axvline(event_time, color='red', linestyle='-')

对于所有 y 值,如何在 x = event_time 处显示垂直线?

【问题讨论】:

    标签: pandas python-2.7 datetime plot time-series


    【解决方案1】:

    plt一起工作

    ax = df_stats_t.plot(x = 't', y='t_TI_var_pwr', linestyle='none', color = 'black', marker = 'o')
    ax1 = ax.twinx()
    df_stats_t.plot(x='t',y='t_TI_var_ws',ax=ax1, linestyle='none', color = 'green', marker = 'o')
    plt.axvline(event_time, color='red', linestyle='-')
    

    【讨论】:

      猜你喜欢
      • 2022-01-12
      • 2017-07-13
      • 2020-09-28
      • 2021-12-28
      • 1970-01-01
      • 2022-12-13
      • 2013-10-13
      • 2013-07-17
      • 2021-04-25
      相关资源
      最近更新 更多