How to use ipympl - 10 common examples

To help you get started, we’ve selected a few ipympl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github glue-viz / glue-jupyter / glue_jupyter / matplotlib / base.py View on Github external
def __init__(self, session, parent=None, wcs=None, state=None):

        self.figure = Figure()
        self.canvas = Canvas(self.figure)
        self.canvas.manager = FigureManager(self.canvas, 0)
        self.figure, self.axes = init_mpl(self.figure, wcs=wcs)

        # FIXME: The following is required for now for the tools to work
        self.central_widget = self.figure
        self._axes = self.axes

        super(MatplotlibJupyterViewer, self).__init__(session, state=state)

        MatplotlibViewerMixin.setup_callbacks(self)

        self.css_widget = HTML(REMOVE_TITLE_CSS)

        self.create_layout()
github matplotlib / jupyter-matplotlib / ipympl / backend_nbagg.py View on Github external
def new_figure_manager_given_figure(num, figure):
    """
    Create a new figure manager instance for the given figure.
    """
    from matplotlib._pylab_helpers import Gcf

    def closer(event):
        Gcf.destroy(num)

    canvas = Canvas(figure)
    if 'nbagg.transparent' in set(rcParams.keys()) and rcParams['nbagg.transparent']:
        figure.patch.set_alpha(0)
    manager = FigureManager(canvas, num)

    if is_interactive():
        manager.show()
        figure.canvas.draw_idle()

    canvas.mpl_connect('close_event', closer)

    return manager
github holoviz / panel / panel / pane / plot.py View on Github external
def _get_widget(self, fig):
        import matplotlib
        old_backend = getattr(matplotlib.backends, 'backend', 'agg')

        from ipympl.backend_nbagg import FigureManager, Canvas, is_interactive
        from matplotlib._pylab_helpers import Gcf

        matplotlib.use(old_backend)

        def closer(event):
            Gcf.destroy(0)

        canvas = Canvas(fig)
        fig.patch.set_alpha(0)
        manager = FigureManager(canvas, 0)

        if is_interactive():
            fig.canvas.draw_idle()

        canvas.mpl_connect('close_event', closer)
        return manager
github holoviz / panel / panel / pane / plot.py View on Github external
def _get_widget(self, fig):
        import matplotlib
        old_backend = getattr(matplotlib.backends, 'backend', 'agg')

        from ipympl.backend_nbagg import FigureManager, Canvas, is_interactive
        from matplotlib._pylab_helpers import Gcf

        matplotlib.use(old_backend)

        def closer(event):
            Gcf.destroy(0)

        canvas = Canvas(fig)
        fig.patch.set_alpha(0)
        manager = FigureManager(canvas, 0)

        if is_interactive():
            fig.canvas.draw_idle()

        canvas.mpl_connect('close_event', closer)
        return manager
github matplotlib / jupyter-matplotlib / ipympl / backend_nbagg.py View on Github external
def new_figure_manager_given_figure(num, figure):
    """
    Create a new figure manager instance for the given figure.
    """
    from matplotlib._pylab_helpers import Gcf

    def closer(event):
        Gcf.destroy(num)

    canvas = Canvas(figure)
    if 'nbagg.transparent' in set(rcParams.keys()) and rcParams['nbagg.transparent']:
        figure.patch.set_alpha(0)
    manager = FigureManager(canvas, num)

    if is_interactive():
        manager.show()
        figure.canvas.draw_idle()

    canvas.mpl_connect('close_event', closer)

    return manager
github glue-viz / glue-jupyter / glue_jupyter / matplotlib / base.py View on Github external
def __init__(self, session, parent=None, wcs=None, state=None):

        self.figure = Figure()
        self.canvas = Canvas(self.figure)
        self.canvas.manager = FigureManager(self.canvas, 0)
        self.figure, self.axes = init_mpl(self.figure, wcs=wcs)

        # FIXME: The following is required for now for the tools to work
        self.central_widget = self.figure
        self._axes = self.axes

        super(MatplotlibJupyterViewer, self).__init__(session, state=state)

        MatplotlibViewerMixin.setup_callbacks(self)

        self.css_widget = HTML(REMOVE_TITLE_CSS)

        self.create_layout()
github glue-viz / glue-jupyter / glue_jupyter / matplotlib / base.py View on Github external
FigureManagerNbAgg as FigureManager)

from matplotlib.figure import Figure

from glue.viewers.matplotlib.mpl_axes import init_mpl
from glue.viewers.matplotlib.state import MatplotlibDataViewerState
from glue.viewers.matplotlib.viewer import MatplotlibViewerMixin

from glue.utils.matplotlib import DEFER_DRAW_BACKENDS

from glue_jupyter.view import IPyWidgetView

__all__ = ['MatplotlibJupyterViewer']

# Register the Qt backend with defer_draw
DEFER_DRAW_BACKENDS.append(Canvas)

# By default, the Jupyter Matplotlib widget has a big clunky title bar, so
# we apply custom CSS to remove it.
REMOVE_TITLE_CSS = "<style> .output_wrapper .ui-dialog-titlebar { display: none; } </style>"


class MatplotlibJupyterViewer(MatplotlibViewerMixin, IPyWidgetView):

    _state_cls = MatplotlibDataViewerState

    large_data_size = None

    def __init__(self, session, parent=None, wcs=None, state=None):

        self.figure = Figure()
        self.canvas = Canvas(self.figure)
github xoolive / traffic / traffic / drawing / ipywidgets.py View on Github external
def __init__(self, traffic: Traffic, projection=EuroPP()) -> None:

        ipython = get_ipython()
        ipython.magic("matplotlib ipympl")
        from ipympl.backend_nbagg import FigureCanvasNbAgg, FigureManagerNbAgg

        self.fig_map = Figure(figsize=(6, 6))
        self.fig_time = Figure(figsize=(6, 4))

        self.canvas_map = FigureCanvasNbAgg(self.fig_map)
        self.canvas_time = FigureCanvasNbAgg(self.fig_time)

        self.manager_map = FigureManagerNbAgg(self.canvas_map, 0)
        self.manager_time = FigureManagerNbAgg(self.canvas_time, 0)

        layout = {"width": "590px", "height": "800px", "border": "none"}
        self.output = Output(layout=layout)

        self._traffic = traffic
        self.t_view = traffic.sort_values("timestamp")
        self.trajectories: Dict[str, List[Artist]] = defaultdict(list)

        self.create_map(projection)

        self.projection = Dropdown(options=["EuroPP", "Lambert93", "Mercator"])
        self.projection.observe(self.on_projection_change)
github xoolive / traffic / traffic / drawing / ipywidgets.py View on Github external
def __init__(self, traffic: Traffic, projection=EuroPP()) -> None:

        ipython = get_ipython()
        ipython.magic("matplotlib ipympl")
        from ipympl.backend_nbagg import FigureCanvasNbAgg, FigureManagerNbAgg

        self.fig_map = Figure(figsize=(6, 6))
        self.fig_time = Figure(figsize=(6, 4))

        self.canvas_map = FigureCanvasNbAgg(self.fig_map)
        self.canvas_time = FigureCanvasNbAgg(self.fig_time)

        self.manager_map = FigureManagerNbAgg(self.canvas_map, 0)
        self.manager_time = FigureManagerNbAgg(self.canvas_time, 0)

        layout = {"width": "590px", "height": "800px", "border": "none"}
        self.output = Output(layout=layout)

        self._traffic = traffic
        self.t_view = traffic.sort_values("timestamp")
        self.trajectories: Dict[str, List[Artist]] = defaultdict(list)

        self.create_map(projection)

        self.projection = Dropdown(options=["EuroPP", "Lambert93", "Mercator"])
        self.projection.observe(self.on_projection_change)
github xoolive / traffic / traffic / drawing / ipywidgets.py View on Github external
def __init__(self, traffic: Traffic, projection=EuroPP()) -> None:

        ipython = get_ipython()
        ipython.magic("matplotlib ipympl")
        from ipympl.backend_nbagg import FigureCanvasNbAgg, FigureManagerNbAgg

        self.fig_map = Figure(figsize=(6, 6))
        self.fig_time = Figure(figsize=(6, 4))

        self.canvas_map = FigureCanvasNbAgg(self.fig_map)
        self.canvas_time = FigureCanvasNbAgg(self.fig_time)

        self.manager_map = FigureManagerNbAgg(self.canvas_map, 0)
        self.manager_time = FigureManagerNbAgg(self.canvas_time, 0)

        layout = {"width": "590px", "height": "800px", "border": "none"}
        self.output = Output(layout=layout)

        self._traffic = traffic
        self.t_view = traffic.sort_values("timestamp")
        self.trajectories: Dict[str, List[Artist]] = defaultdict(list)

        self.create_map(projection)

        self.projection = Dropdown(options=["EuroPP", "Lambert93", "Mercator"])
        self.projection.observe(self.on_projection_change)

        self.identifier_input = Text(description="Callsign/ID")
        self.identifier_input.observe(self.on_id_input)