Skip to content
Advertisement

How to plot the sum of two animated sine waves in python?

Code:-

JavaScript

This is the code I have tried to attain the result. But it u is static, that is it prints the final plot, and it only prints in a temporary window and closes after execution of the code.

But I need an answer which have three waves in the same output, where the first sine wave and second sine wave is added to obtain the final sine wave.

I want an answer which will be animated using numpy, matplotlib library of Python language.

I looked through subplot examples but I couldn’t merge the subplot module of matplotlib library with animation module of the matplotlib library.

Also, how can we save all the plots of the sine waves as a gif in local directory?

What library is required to export all three waves in a single gif file like the image? Anyone have a solution for this? Expected animated gif file

Advertisement

Answer

Check out this solution

  • To plot the sum of two sinusoidal in Python, I have used Matplotlib and NumPy to generate animated sine waves and exported the output as a gif file.
  • It is a customizable code where the equations and variables for X-axis and Y-axis can be changed in the animate() function.

Python code

JavaScript

Output (gif file)

Plotting Animated sum of two sinusoids in Python

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement