mpl_interactions.jupyter.interactive_plot¶
-
interactive_plot
(f, x=None, x_scale='stretch', y_scale='stretch', slider_format_string='{:.1f}', plot_kwargs=None, title=None, figsize=None, display=True, **kwargs)[source]¶ Make a plot interactive using sliders. just pass the keyword arguments of the function you want to plot to this function like so:
- Parameters
x (arraylike or None) – x values a which to evaluate the function. If None the function(s) f should return a list of [x, y]
ax (matplolibt.Axes or None) – axes on which to
x_scale (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.
y_scale (string or tuple of floats, optional) – If a tuple it will be passed to ax.set_ylim. Other options are same as x_scale
slider_format_string (string | dictionary) – A valid format string, this will be used to render the current value of the parameter. To control on a per slider basis pass a dictionary of format strings with the parameter names as the keys.
plot_kwargs (None, dict, or iterable of dicts) – Keyword arguments to pass to plot. If using multiple f’s then plot_kwargs must be either None or be iterable.
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}’
figsize (tuple or scalar) – If tuple it will be used as the matplotlib figsize. If a number then it will be used to scale the current rcParams figsize
display (boolean) – If True then the output and controls will be automatically displayed
- Returns
fig (matplotlib figure)
ax (matplotlib axis)
controls (list of slider widgets)
Examples
With numpy arrays:
x = np.linspac(0,2*np.pi) tau = np.linspace(0, np.pi) def f(x, tau): return np.sin(x+tau) interactive_plot(f, x=x, tau=tau)
with tuples:
x = np.linspac(0,2*np.pi) def f(x, tau): return np.sin(x+tau) interactive_plot(f, x=x, tau=(0, np.pi, 1000))