I used matplotlib to create some plot, which depends on 8 variables. I would like to study how the plot changes when I change some of them. I created some script that calls the matplotlib one and generates different snapshots that later I convert into a movie, it is not bad, but a bit clumsy.
-
I wonder if somehow I could interact with the plot regeneration using keyboard keys to increase / decrease values of some of the variables and see instantly how the plot changes.
-
What is the best approach for this?
-
Also if you can point me to interesting links or a link with a plot example with just two sliders?
In addition to what @triplepoint mentioned, have a look at the slider widget.
There’s an example on the matplotlib examples page. It’s a graphical slider bar rather than keyboard bindings, but it works quite well for what you want to do.
Also note that to guarantee the sliders and buttons remain responsive and not garbage-collected, references to the objects (
amp_slider,freq_slider, etc.) should be maintained by yourself.(I’m making this community wiki, as I’m just copy-pasting from the example.
This particular example teaches bad habits (e.g.The example has been fixed to avoid the use offrom pylab import *), but it gets the point across.pylab.)