Interactive Mode
You may have noticed that you’ve been using plt.show()
at the end of all of your scripts to show the plot on your screen. matplotlib
supports interactive mode. In this mode, you don’t have to have to use plt.show()
to display the plot or plt.draw()
to update it.
When interactive mode is on, the backend in charge of applying changes to your plot will automatically pop up and update the plot when you do. Interactive mode is off by default. Here’s how to check if it’s on:
>>> plt.isinteractive()
00:00
At this point, you’ve probably noticed that we’ve been using plt.show()
at the end of all of our scripts. We’ve been using this to show the plot onscreen.
00:13
Well, Matplotlib supports what’s called interactive mode. In this mode, you don’t actually have to use plt.show()
in order to display the plot or plt.draw()
to update it.
00:28 When interactive mode is on, the backend in charge of actually applying the changes to our plot will automatically pop up and update the plot when we do.
00:42
Interactive mode is off by default. We can check its status at any time with plt.isinteractive()
and toggle it with plt.ion()
to turn it on and plt.ioff()
to turn it off.
00:59 As a try-it-at-home exercise, run this code in your interactive shell. Then run this code again, but without the first and last lines, and see how things change.
01:13 If you’ve done it right, the plot should appear onscreen and update by itself as you continue to call functions and methods. You can literally build your plot interactively, all from within the Python shell.
Become a Member to join the conversation.