【问题标题】:Adding horizontal lines to timeseries plot with python + matplotlib使用 python + matplotlib 在时间序列图中添加水平线
【发布时间】:2021-01-03 13:06:04
【问题描述】:

我正在绘制时间序列中的数据,我想添加多条水平线,表示值阈值。

你建议怎么做?

date_today = datetime.now()
date_rng = pd.date_range(start='1/1/1989', end='1/2/1989', freq='H')[:-1]
np.random.seed(seed=100)
data1 = np.random.randint(1, high=100, size=len(date_rng))
data2 = np.random.randint(1, high=100, size=len(date_rng))
df = pd.DataFrame({'datetime': date_rng, 'col1': data1, 'col2': data2})
df = df.set_index('datetime')
df.plot(figsize=(10, 5));

【问题讨论】:

  • 查看axhline的文档。

标签: python matplotlib plot time-series


【解决方案1】:

你可以像这样使用 axhline:

plt.axhline(xmin,xmax,y)

https://matplotlib.org/3.3.1/api/_as_gen/matplotlib.pyplot.axhline.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-24
    • 1970-01-01
    • 2018-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-26
    相关资源
    最近更新 更多