Skip to content

registering

Register plotly-resampler to (un)wrap plotly-graph-objects.

register_plotly_resampler(mode='auto', **aggregator_kwargs)

Register plotly-resampler to plotly.graph_objects.

This function results in the use of plotly-resampler under the hood.

Note

We advise to use mode= widget when working in an IPython based environment as this will just behave as a go.FigureWidget, but with dynamic aggregation. When using mode= auto or figure; most figures will be wrapped as FigureResampler, on which show_dash needs to be called.

Note

This function is mostly useful for notebooks. For dash-apps, we advise to look at the dash app examples on GitHub

Parameters:

Name Type Description Default
mode str

The mode of the plotly-resampler. Possible values are: ‘auto’, ‘figure’, ‘widget’, None. If ‘auto’ is used, the mode is determined based on the environment; if it is in an IPython environment, the mode is ‘widget’, otherwise it is ‘figure’. If ‘figure’ is used, all plotly figures are wrapped as FigureResampler objects. If ‘widget’ is used, all plotly figure widgets are wrapped as FigureWidgetResampler objects (we advise to use this mode in IPython environment with a kernel). If None is used, wrapping is done as expected (go.Figure -> FigureResampler, go.FigureWidget -> FigureWidgetResampler).

'auto'
aggregator_kwargs dict

The keyword arguments to pass to the plotly-resampler decorator its constructor. See more details in FigureResampler and FigureWidgetResampler.

{}
Source code in plotly_resampler/registering.py
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
def register_plotly_resampler(mode="auto", **aggregator_kwargs):
    """Register plotly-resampler to plotly.graph_objects.

    This function results in the use of plotly-resampler under the hood.

    !!! note
        We advise to use mode= ``widget`` when working in an IPython based environment
        as this will just behave as a ``go.FigureWidget``, but with dynamic aggregation.
        When using mode= ``auto`` or ``figure``; most figures will be wrapped as
        [`FigureResampler`][figure_resampler.FigureResampler], on which
        [`show_dash`][figure_resampler.FigureResampler.show_dash] needs to be called.

    !!! note
        This function is mostly useful for notebooks. For dash-apps, we advise to look
        at the dash app examples on [GitHub](https://github.com/predict-idlab/plotly-resampler/tree/main/examples#2-dash-apps)

    Parameters
    ----------
    mode : str, optional
        The mode of the plotly-resampler.
        Possible values are: 'auto', 'figure', 'widget', None.
        If 'auto' is used, the mode is determined based on the environment; if it is in
        an IPython environment, the mode is 'widget', otherwise it is 'figure'.
        If 'figure' is used, all plotly figures are wrapped as FigureResampler objects.
        If 'widget' is used, all plotly figure widgets are wrapped as
        FigureWidgetResampler objects (we advise to use this mode in IPython environment
        with a kernel).
        If None is used, wrapping is done as expected (go.Figure -> FigureResampler,
        go.FigureWidget -> FigureWidgetResampler).
    aggregator_kwargs : dict, optional
        The keyword arguments to pass to the plotly-resampler decorator its constructor.
        See more details in [`FigureResampler`][figure_resampler.FigureResampler] and
        [`FigureWidgetResampler`][figure_resampler.FigureWidgetResampler].

    """
    for constr_name, pr_class in PLOTLY_CONSTRUCTOR_WRAPPER.items():
        if (mode == "auto" and _is_ipython_env()) or mode == "widget":
            pr_class = FigureWidgetResampler
        elif mode == "figure":
            pr_class = FigureResampler
        # else: default mode -> wrap according to PLOTLY_CONSTRUCTOR_WRAPPER

        for module in PLOTLY_MODULES:
            _register_wrapper(module, constr_name, pr_class, **aggregator_kwargs)

unregister_plotly_resampler()

Unregister plotly-resampler from plotly.graph_objects.

Source code in plotly_resampler/registering.py
138
139
140
141
142
def unregister_plotly_resampler():
    """Unregister plotly-resampler from plotly.graph_objects."""
    for constr in PLOTLY_CONSTRUCTOR_WRAPPER.keys():
        for module in PLOTLY_MODULES:
            _unregister_wrapper(module, constr)