0

I have 2 arrays:

tiempos dtype='datetime64[ns]'
valores dtype=float32

I want to use plt.fill_between to color some parts of the graphic

fig = plt.figure(figsize=(14, 8))

plt.fill_between(tiempos,valores.where(valores>=0.5), 0.5, color='red', alpha=0.8)
plt.fill_between(tiempos, valores.where(valores<=-0.5), -0.5, color='blue', alpha=0.3)

plt.plot(tiempos,valores,color='black')

But when i run the code i get this error:

AttributeError: 'numpy.ndarray' object has no attribute 'where'

How can i plot this with those two arrays?

Thanks in advance.

Javier
  • 493
  • 3
  • 15
  • 1
    `.where(...)` is not an array method. The method resides in the top level namespace `np.where(valores,...)` [`np.where`](https://numpy.org/doc/stable/reference/generated/numpy.where.html) – Trenton McKinney Nov 25 '21 at 05:59
  • can you provide an image what should your plot look like ? – manaclan Nov 25 '21 at 06:25
  • You can try `plt.fill_between(tiempos, valores, 0.5, where=valores >= 0.5, ...)`. Note that the syntax is `plt.fill_between(x, y0, y1, ...)` and that both `y0` and `y1` need to either be scalars or arrays of the same length as `x`. – JohanC Nov 25 '21 at 06:33

0 Answers0