mpl_interactions.interactive_plot¶
-
mpl_interactions.
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)¶ Make a plot interactive using sliders. just pass the keyword arguments of the function you want to plot to this function like so:
- Parameters
- xarraylike or None
x values a which to evaluate the function. If None the function(s) f should return a list of [x, y]
- axmatplolibt.Axes or None
axes on which to
- x_scalestring 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_scalestring 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_stringstring | 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_kwargsNone, 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.
- titleNone 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}’
- figsizetuple 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
- displayboolean
If True then the output and controls will be automatically displayed
- Returns
- figmatplotlib figure
- axmatplotlib axis
- controlslist of slider widgets
Examples
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)
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))