mpl_interactions.interactive_plot

interactive_plot(*args, parametric=False, multiline=False, ax=None, slider_formats=None, title=None, xlim='stretch', ylim='stretch', force_ipywidgets=False, play_buttons=False, play_button_pos='right', controls=None, display_controls=True, **kwargs)[source]

Control a plot using widgets

interactive_plot([x], y, [fmt])

where x/y is are either arraylike or a function that returns arrays. Any kwargs accepted by matplotlib.pyplot.plot will be passed through, other kwargs will be intrepreted as controls

Parameters
  • x, y (array-like or scalar or function) – The horizontal / vertical coordinates of the data points. x values are optional and default to range(len(y)). If both x and y are provided and y is a function then it will be called as y(x, **params). If x is a function it will be called as x(**params)

  • fmt (str, optional) – A format string, e.g. ‘ro’ for red circles. See matplotlib.pyplot.plot for full documentation. as xlim

  • parametric (boolean) – If True then the function expects to have only received a value for y and that that function will return an array for both x and y, or will return an array with shape (N, 2)

  • ax (matplotlib axis, optional) – The axis on which to plot. If none the current axis will be used.

  • slider_formats (None, string, or dict) – If None a default value of decimal points will be used. Uses the new {} style formatting

  • title (None or string) – If a string then you can have it update automatically using string formatting of the names of the parameters. i.e. to include the current value of tau: title=’the value of tau is: {tau:.2f}’

  • xlim (string or tuple of floats, optional) – If a tuple it will be passed to ax.set_xlim. Other options are: ‘auto’: rescale the x axis for every redraw ‘stretch’: only ever expand the xlims.

  • ylim (string or tuple of floats, optional) – If a tuple it will be passed to ax.set_ylim. Other options are same as xlim

  • force_ipywidgets (boolean) – If True ipywidgets will always be used, even if not using the ipympl backend. If False the function will try to detect if it is ok to use ipywidgets If ipywidgets are not used the function will fall back on matplotlib widgets

  • play_buttons (bool or dict, optional) – Whether to attach an ipywidgets.Play widget to any sliders that get created. If a boolean it will apply to all kwargs, if a dictionary you choose which sliders you want to attach play buttons too.

  • play_button_pos (str, or dict, or list(str)) – ‘left’ or ‘right’. Whether to position the play widget(s) to the left or right of the slider(s)

  • controls (mpl_interactions.controller.Controls) – An existing controls object if you want to tie multiple plot elements to the same set of controls

  • display_controls (boolean) – Whether the controls should display themselve on creation. Ignored if controls is specified.

Returns

controls

Examples

With numpy arrays:

x = np.linspace(0,2*np.pi)
tau = np.linspace(0, np.pi)
def f(tau):
    return np.sin(x*tau)
interactive_plot(f, tau=tau)

with tuples:

x = np.linspace(0,2*np.pi)
def f(x, tau):
    return np.sin(x+tau)
interactive_plot(x, f, tau=(0, np.pi, 1000))