In [2]:
import matplotlib.pyplot as plt
import numpy as np
In [23]:
nmax=100
x = np.linspace(0,10,nmax)
y = 100*np.random.rand(nmax)
In [31]:
limiter = 4
plt.plot(x,y, 'k.-')
plt.axhline(70, c='m', ls='--')
plt.axhline(20, c='m', ls='--')
plt.grid()
In [25]:
#Perform linear interpolation
from scipy import interpolate
f = interpolate.interp1d(x, y)
In [ ]:
 
In [26]:
new_nmax = 1000 #arbitrary value
xnew = np.linspace(0,10,nmax*new_nmax)
ynew = f(xnew)
In [27]:
#Failed attempt
mask=ynew>limiter
plt.plot(xnew[mask],ynew[mask], 'b-')
plt.plot(xnew[~mask],ynew[~mask], 'r-')
Out[27]:
[<matplotlib.lines.Line2D at 0x7fcd62fd3cc0>]
In [28]:
ynew
Out[28]:
array([32.47884619, 32.53108479, 32.58332339, ..., 64.05227441,
       64.04368815, 64.03510189])
In [30]:
upper = 70
lower = 10

s = ynew.copy()
t = xnew.copy()

supper = np.ma.masked_where(s < upper, s)
slower = np.ma.masked_where(s > lower, s)
smiddle = np.ma.masked_where((s < lower) | (s > upper), s)

fig, ax = plt.subplots()
ax.plot(t, smiddle, t, slower, t, supper)
#plt.grid()
plt.show()
In [ ]:
 
In [ ]:
 
In [ ]:
 
In [ ]: