popt, pcov = curve_fit(fourier, z, Ua, [1.0] * 15)
fig = plt.figure()
ax1 = fig.add_subplot(111)
p1, = plt.plot(z, Ua)
p2, = plt.plot(z, fourier(z, *popt))
p3, = plt.plot(z, fourier(z, popt[0], popt[1], popt[2]))
plt.show()
Create scipy curve fitting definitions for fourier series dynamically