Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions lib/matplotlib/backend_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class FigureManager(cbook.EventEmitter):
canvas : `matplotlib.backend_bases.FigureCanvasBase`
The GUI element on which we draw.

figure : `matplotlib.figure.Figure`
The figure that holds the canvas

toolbar : `matplotlib.backend_bases.NavigationToolbar2`
The toolbar used for interacting with the figure.

Expand All @@ -79,14 +82,14 @@ def __init__(self, figure, num):
self.window = self._backend.Window('Figure %d' % num)
self.window.mpl_connect('window_destroy_event', self.destroy)

self.canvas = self._backend.FigureCanvas(figure, manager=self)
self.figure = figure

w = int(self.canvas.figure.bbox.width)
h = int(self.canvas.figure.bbox.height)
w = int(self.figure.bbox.width)
h = int(self.figure.bbox.height)

self.window.add_element(self.canvas, True, 'center')
self.window.add_element(self.figure.canvas, True, 'center')

self.toolmanager = ToolManager(self.canvas)
self.toolmanager = ToolManager(self.figure.canvas)
self.toolbar = self._get_toolbar()

tools.add_tools_to_manager(self.toolmanager)
Expand All @@ -108,7 +111,24 @@ def notify_axes_change(fig):
'this will be called whenever the current axes is changed'
if self.toolmanager is None and self.toolbar is not None:
self.toolbar.update()
self.canvas.figure.add_axobserver(notify_axes_change)
self.figure.add_axobserver(notify_axes_change)

@property
def figure(self):
return self._figure

@figure.setter
def figure(self, figure):
if hasattr(self, '_figure'):
raise NotImplementedError

if not figure.canvas:
self._backend.FigureCanvas(figure, manager=self)
self._figure = figure

@property
def canvas(self):
return self._figure.canvas
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do allow for self._figure = None then this will error...


def destroy(self, *args):
"""Called to destroy this FigureManager.
Expand All @@ -120,7 +140,7 @@ def destroy(self, *args):
return

self._destroying = True
self.canvas.destroy()
self.figure.canvas.destroy()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again error here if we allow for figure = None.

if self.toolbar:
self.toolbar.destroy()
self.window.destroy()
Expand Down