Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
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()