I am adapting this example to interact with a plot using matplotlib
's widgets.
The way I normally work is interactive, from within spyder
I just call a function that does the plotting.
My goal is to make an executable available to users who do not have Python
installed, so as an intermediate step I am wrapping the functions into a script.
I have minimal experience with standalone scripts, so in a nutshell mine looks like this:
import various_modules
def plotting()
...
plot_some_initial_stuff
sl = Slider()
plt.show() <-------
def update()
...
ax.set_ydata()
fig.canvas.draw_idle()
sl.on_change(update)
return()
plotting()
So I just define the plotting function and then call it.
I had to add the plt.show()
command, which I do not need to have when I'm working from the IPython
shell, otherwise doing:
python my_plot.py
would not produce anything. By adding plt.show()
, the window shows up with the graphs I define in the initialization part. However, no interaction happens.
What is the correct way of achieving interaction when running a script like I'm doing?