user3817989
user3817989

Reputation: 763

How to show the integration plot

I have a written a program which creates following plot. To draw the following plot I have data in two arrays.

enter image description here

In the same plot I want to show the integration plot which looks like following image. Integration plot shows using red line. Can anyone help me to do that. I am using matplotlib to print the first plot.

enter image description here

Upvotes: 0

Views: 3765

Answers (1)

GJStein
GJStein

Reputation: 658

Take a look at the scipy.integrate.cumtrapz function. This will do exactly what you want. If you have two arrays x and y, you can pass them so that the integrated signal y_int is given by:

y_int = integrate.cumtrapz(y, x, initial=0)

This is taken directly from the scipy documentation at this link.

Plotting should then be as easy as calling plt.plot(x, y, x, y_int).

Also, this code assumes that you have done the following imports:

from scipy import integrate
import matplotlib.pyplot as plt

Upvotes: 1

Related Questions