interactive_hist(arr, density=False, bins='auto', weights=None, ax=None, slider_formats=None, force_ipywidgets=False, play_buttons=False, controls=None, display_controls=True, **kwargs)[source]

Control the contents of a histogram using widgets.

See for a discussion of the limitations of this function. These limitations will be improved once has been merged.

  • arr (arraylike or function) – The array or the funciton that returns an array that is to be histogrammed

  • density (bool, optional) – whether to plot as a probability density. Passed to np.histogram

  • bins (int or sequence of scalars or str, optional) – bins argument to np.histogram

  • weights (array_like, optional) – passed to np.histogram

  • 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

  • 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 str 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.

    • None: no sliders

    • True: sliders on the lft

    • False: no sliders

    • ‘left’: sliders on the left

    • ‘right’: sliders on the right

  • 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.




With numpy arrays:

loc = np.linspace(-5, 5, 500)
scale = np.linspace(1, 10, 100)
def f(loc, scale):
    return np.random.randn(1000)*scale + loc
interactive_hist(f, loc=loc, scale=scale)

with tuples:

def f(loc, scale):
    return np.random.randn(1000)*scale + loc
interactive_hist(f, loc=(-5, 5, 500), scale=(1, 10, 100))