1

I'm trying to make a graph I've generated a little more useful in comparisons. Is there a way to make something like I've pictured below? Or possibly a way to draw a line across along the y value of the max and min?

I've tried using max() and min() and placing it in a plot like so:

plt.plot(dat[0]['end_date'], max(dat[0]['pct']))

Which throws a value error because the x list has something like 48 entries whereas the y list would only have one.

ValueError: x and y must have same first dimension, but have shapes (48,) and (1,)

Could I use some version of this that somehow fills the remaining 47 spaces with that same max value?

Thank you!

Mentioned Above

  • Yes. Use this SO answer as an example to draw any line on a plot: https://stackoverflow.com/a/36479941/6067379 – merit_2 Jan 23 '20 at 03:02

1 Answers1

2

You can use plt.axhline():

plt.axhline(max(dat[0]['pct']))
plt.axhline(min(dat[0]['pct']))

Demonstration using random data:

import matplotlib.pyplot as plt
import numpy as np, pandas as pd

df = pd.DataFrame({'x':[np.random.randint(0,10) for i in range(10)]})
df.plot()
plt.axhline(df.x.max())
plt.axhline(df.x.min())

Result: enter image description here

mechanical_meat
  • 163,903
  • 24
  • 228
  • 223