1

I am plotting data from a time series and I would like to add multiple horizontal lines, indicating value thresholds.

How do you recommend going about it?

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));

tti

1
  • 2
    Check the docs for axhline. Commented Sep 16, 2020 at 16:38

1 Answer 1

1

You can use the axhline like this:

plt.axhline(xmin,xmax,y)

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.