I would like to use the ipython notebook widgets to add some degree of interactivity to inline matplotlib plots.
In general the plot can be quite heavy and I want to on
You can do this in a very strait forward way using the new(ish) notebook
backend
%matplotlib notebook
import matplotlib.pyplot as plt
from IPython.html.widgets import interactive
fig, ax = plt.subplots()
ax.plot(range(5))
vline = ax.axvline(1, color='k')
hline = ax.axhline(0.5, color='k')
def set_cursor(x, y):
vline.set_xdata((x, x))
hline.set_ydata((y, y))
ax.figure.canvas.draw_idle()
and in a separate cell:
interactive(set_cursor, x=ax.get_xlim(), y=ax.get_ylim())
This will still re-draw the entire figure every time you move the cursor because notebook
does not currently support blitting (which is being worked on https://github.com/matplotlib/matplotlib/pull/4290 )