matplotlib.pyplot.
install_repl_displayhook
Install a repl display hook so that any stale figure are automatically redrawn when control is returned to the repl.
This works with IPython terminals and kernels, as well as vanilla python shells.