8000 Move notify_axes_change to FigureManagerBase class. · matplotlib/matplotlib@3df2055 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 3df2055

Browse files
committed
Move notify_axes_change to FigureManagerBase class.
... instead of duplicating it across backends. The additional cost on non-interactive backends is likely negligible.
1 parent e188fae commit 3df2055

File tree

6 files changed

+10
-33
lines changed

6 files changed

+10
-33
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2674,6 +2674,15 @@ def __init__(self, canvas, num):
26742674
'key_press_event',
26752675
self.key_press)
26762676

2677+
self.toolmanager = None
2678+
self.toolbar = None
2679+
2680+
@self.canvas.figure.add_axobserver
2681+
def notify_axes_change(fig):
2682+
# Called whenever the current axes is changed.
2683+
if self.toolmanager is None and self.toolbar is not None:
2684+
self.toolbar.update()
2685+
26772686
def show(self):
26782687
"""
26792688
For GUI backends, show the figure window and redraw.

lib/matplotlib/backends/_backend_tk.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -487,14 +487,6 @@ def __init__(self, canvas, num, window):
487487

488488
self._shown = False
489489

490-
def notify_axes_change(fig):
491-
'this will be called whenever the current axes is changed'
492-
if self.toolmanager is not None:
493-
pass
494-
elif self.toolbar is not None:
495-
self.toolbar.update()
496-
self.canvas.figure.add_axobserver(notify_axes_change)
497-
498490
def _get_toolbar(self):
499491
if matplotlib.rcParams['toolbar'] == 'toolbar2':
500492
toolbar = NavigationToolbar2Tk(self.canvas, self.window)

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -394,14 +394,6 @@ def destroy(*args):
394394
self.window.show()
395395
self.canvas.draw_idle()
396396

397-
def notify_axes_change(fig):
398-
'this will be called whenever the current axes is changed'
399-
if self.toolmanager is not None:
400-
pass
401-
elif self.toolbar is not None:
402-
self.toolbar.update()
403-
self.canvas.figure.add_axobserver(notify_axes_change)
404-
405397
self.canvas.grab_focus()
406398

407399
def destroy(self, *args):

lib/matplotlib/backends/backend_macosx.py

Lines changed: 1 addition & 6 deletions
< 10000 td data-grid-cell-id="diff-fa0b9840f8945ba1ad40628be14617bd8d2f06a3e8c1e2791e5d8e60799488e0-130-130-2" data-line-anchor="diff-fa0b9840f8945ba1ad40628be14617bd8d2f06a3e8c1e2791e5d8e60799488e0R130" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);padding-right:24px" tabindex="-1" valign="top" class="focusable-grid-cell diff-text-cell right-side-diff-cell left-side">
title = "Figure %d" % num
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,13 @@ def __init__(self, canvas, num):
129129
FigureManagerBase.__init__(self, canvas, num)
130130
131131
_macosx.FigureManager.__init__(self, canvas, title)
132-
if rcParams['toolbar']=='toolbar2':
132+
if rcParams['toolbar'] == 'toolbar2':
133133
self.toolbar = NavigationToolbar2Mac(canvas)
134134
else:
135135
self.toolbar = None
136136
if self.toolbar is not None:
137137
self.toolbar.update()
138138

139-
def notify_axes_change(fig):
140-
'this will be called whenever the current axes is changed'
141-
if self.toolbar != None: self.toolbar.update()
142-
self.canvas.figure.add_axobserver(notify_axes_change)
143-
144139
if matplotlib.is_interactive():
145140
self.show()
146141
self.canvas.draw_idle()

lib/matplotlib/backends/backend_qt5.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -620,11 +620,6 @@ def __init__(self, canvas, num):
620620
self.window.show()
621621
self.canvas.draw_idle()
622622

623-
def notify_axes_change(fig):
624-
# This will be called whenever the current axes is changed
625-
if self.toolbar is not None:
626-
self.toolbar.update()
627-
self.canvas.figure.add_axobserver(notify_axes_change)
628623
self.window.raise_()
629624

630625
def full_screen_toggle(self):

lib/matplotlib/backends/backend_wx.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,12 +1285,6 @@ def __init__(self, canvas, num, frame):
12851285
self.tb = frame.GetToolBar()
12861286
self.toolbar = self.tb # consistent with other backends
12871287

1288-
def notify_axes_change(fig):
1289-
'this will be called whenever the current axes is changed'
1290-
if self.tb is not None:
1291-
self.tb.update()
1292-
self.canvas.figure.add_axobserver(notify_axes_change)
1293-
12941288
def show(self):
12951289
self.frame.Show()
12961290
self.canvas.draw()

0 commit comments

Comments
 (0)
0