Matplotlib- plot piecewise Linear Function with three parts
问题 I have some data that I want to fit with a piecewise linear function that has three parts. So something like this if there were two inflection points: Unfortunately, when I use the following code, I do not get the correct data, it instead looks like this Anyone know what's wrong? Thanks! def piecewise_linear2(x, x0, y0, k1, k2, k3): return np.piecewise(x, [x < x0], [lambda x:k1*x + y0-k1*x0, lambda x:k2*x + y0-k2*x0, lambda x:k3*x + y0-k3*x0]) fit_days = np.array([1786,1852,2067,2142,2143