My Coding >
Programming language >
Python >
Python graphics >
Matplotlib >
Matplotlib Widgets >
Interactive Lissajous curves with Matplotlib
Interactive Lissajous curves with MatplotlibOn of the very interesting example of parametric curve is Lissajous curves. Lissajous curves are given by set of parametric equations:
and for clarity, let’s consider A == B == 1. In the previous article about parametric curves with SymPy I’ve make some introduction how to plot parametric curves. And it is possible to plot Lissajous curves with SymPy as well, for example in the code bellow, Lissajous curves for b = 4 and a in range from 1 to 9 are plotted.
But it is very difficult to use this plot for studying Lissajous curves, because it is very interesting to do some adjacent in coefficient and check results, comparing with experiment. Therefore it is necessary to use interactive plot with opportunity to change parameters of the fly. Interactive plottingTo make interactive plotting, it I very convenient to use Slider from matplotlib.widgets library. To make interactive plotting, we need to create list of points in numpy array and use matplotlib to display them.
At the beginning we plotting it for the start position and store resulting curve into 2DLine object. Also it is necessary to declare axis size- to keep plotting within fixed range. At the next step we will initialize positions for sliders for each parameters (a, b, s) and Sliders itself
Also we need to declare behaviour of parameters with slider movement
If you want to send some parameters to function update, you need to do it though lambda call. At the next step it is necessary to declare call up our update function on any changes of the slider
And plot the curve at the end
Watch video about Interactive Lissajous curves to see all details. Interactive Lissajous curves codeThe full code for this Interactive Lissajous plot is here:
|
Last 10 artitles
9 popular artitles
|
|||
© 2020 MyCoding.uk -My blog about coding and further learning. This blog was writen with pure Perl and front-end output was performed with TemplateToolkit. |