def manage_backend(plot_func):
    """
    Decorator for hypertools.plot that prevents unexpected changes to
    matplotlib rcParams (https://github.com/ContextLab/hypertools/issues/243)
    and handles temporarily changing the matplotlib backend for
    interactive and animated plots, as necessary.

    Parameters
    ----------
    plot_func : function
        Function around which to set/reset the plotting backend and
        rcParams (currently, always `hypertools.plot`).

    Returns
    -------
    plot_wrapper : function
        The decorated function.

    Notes
    ------
    1. Capturing & restoring the rcParams needs to happen here rather
       than in `set_interactive_backend` so it's done independently for
       each plot
    2. Written in a slightly roundabout way in order to skip unnecessary
       & duplicate calls when the decorated call to `hypertools.plot`
       happens inside the `hypertools.set_interactive_backend` context.
    """
    @wraps(plot_func)
    def plot_wrapper(*args, **kwargs):
        # record current rcParams
        old_rcParams = mpl.rcParams.copy()
        # assume using the mock-`contextlib.nullcontext` context
        backend_context = _null_backend_context
        tmp_backend = None

        if not IN_SET_CONTEXT:
            plot_kwargs = _get_runtime_args(plot_func, *args, **kwargs)
            if plot_kwargs.get('animate') or plot_kwargs.get('interactive'):
                curr_backend = HypertoolsBackend(mpl.get_backend()).normalize()
                tmp_backend = plot_kwargs.get('mpl_backend')
                if tmp_backend == 'auto':
                    tmp_backend = HYPERTOOLS_BACKEND.normalize()

                if tmp_backend not in ('disable', curr_backend):
                    # if all conditions are met, use the real context
                    backend_context = set_interactive_backend

        try:
            with backend_context(tmp_backend):
                if BACKEND_WARNING is not None:
                    warnings.warn(BACKEND_WARNING)

                return plot_func(*args, **kwargs)

        finally:
            # restore rcParams prior to plot
            with warnings.catch_warnings():
                # if the matplotlibrc was cached from <=v3.3.0, a TON of
                # (harmless as of v3.2.0) MatplotlibDeprecationWarnings
                # about `axes.Axes3D`-related rcParams fields are issued
                warnings.simplefilter('ignore', mpl.MatplotlibDeprecationWarning)
                mpl.rcParams.update(**old_rcParams)

    return plot_wrapper

    Decorator for hypertools.plot that prevents unexpected changes to
    matplotlib rcParams (https://github.com/ContextLab/hypertools/issues/243)
    and handles temporarily changing the matplotlib backend for
    interactive and animated plots, as necessary.

    Parameters
    ----------
    plot_func : function
        Function around which to set/reset the plotting backend and
        rcParams (currently, always `hypertools.plot`).

    Returns
    -------
    plot_wrapper : function
        The decorated function.

    Notes
    ------
    1. Capturing & restoring the rcParams needs to happen here rather
       than in `set_interactive_backend` so it's done independently for
       each plot
    2. Written in a slightly roundabout way in order to skip unnecessary
       & duplicate calls when the decorated call to `hypertools.plot`
       happens inside the `hypertools.set_interactive_backend` context.
    
hypertools/plot/backend.py