How to plot the integral of a signal as time goes by?

matplotlib, numpy, python, scipy

Solution

Try using `scipy.integrate.cumtrapz()` instead :

plt.plot(time[:-1], scipy.integrate.cumtrapz(signal, x=time))
plt.show()

It computes an array containing the cumulative integral values.

http://docs.scipy.org/doc/scipy-0.10.1/reference/generated/scipy.integrate.trapz.html

Problem

I have a time-dependent signal. I wish to plot its integration over time with time being x-axis and integration value being y-axis. Is there any Python way of doing this? To be more specific: I have a time array, `time`, and a signal array, `signal`. They are of same dimension. I need to integrate `signal` over `time` with `scipy.integrate.trapz()`. Instead of getting the final integral, I wish to see the integral varying as time passes.

Original source

Related problems