diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 0f47c4653e1a..96adc3160155 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -3220,13 +3220,6 @@ def __init__(self, manager): # to write into toolbar message self.messagelock = widgets.LockDraw() - for name, tool in tools.tools: - if tool is None: - if self.toolbar is not None: - self.toolbar.add_separator(-1) - else: - self.add_tool(name, tool, None) - self._last_cursor = self._default_cursor @property @@ -3329,6 +3322,22 @@ def remove_tool(self, name): if self.toolbar: self.toolbar._remove_toolitem(name) + def add_tools(self, tools): + """ Add multiple tools to `Navigation` + + Parameters + ---------- + tools : a list of tuples which contains the id of the tool and + a either a reference to the tool Tool class itself, or None to + insert a spacer. See :func:`add_tool`. + """ + for name, tool in tools: + if tool is None: + if self.toolbar is not None: + self.toolbar.add_separator(-1) + else: + self.add_tool(name, tool, None) + def add_tool(self, name, tool, position=None): """Add tool to `Navigation` diff --git a/lib/matplotlib/backends/backend_gtk3.py b/lib/matplotlib/backends/backend_gtk3.py index dab819fa9193..df222fa2a520 100644 --- a/lib/matplotlib/backends/backend_gtk3.py +++ b/lib/matplotlib/backends/backend_gtk3.py @@ -31,7 +31,7 @@ def fn_name(): return sys._getframe(1).f_code.co_name from matplotlib.backend_bases import RendererBase, GraphicsContextBase, \ FigureManagerBase, FigureCanvasBase, NavigationToolbar2, cursors, TimerBase from matplotlib.backend_bases import ShowBase, ToolbarBase, NavigationBase -from matplotlib.backend_tools import SaveFigureBase, ConfigureSubplotsBase +from matplotlib.backend_tools import SaveFigureBase, ConfigureSubplotsBase, tools from matplotlib.cbook import is_string_like, is_writable_file_like from matplotlib.colors import colorConverter @@ -415,6 +415,8 @@ def __init__(self, canvas, num): self.toolbar = self._get_toolbar() self.navigation = self._get_navigation() + if matplotlib.rcParams['toolbar'] == 'navigation': + self.navigation.add_tools(tools) # calculate size for window w = int (self.canvas.figure.bbox.width) diff --git a/lib/matplotlib/backends/backend_tkagg.py b/lib/matplotlib/backends/backend_tkagg.py index a17c0f4c8c13..bbaf35670cf0 100644 --- a/lib/matplotlib/backends/backend_tkagg.py +++ b/lib/matplotlib/backends/backend_tkagg.py @@ -21,7 +21,7 @@ from matplotlib.backend_bases import FigureManagerBase, FigureCanvasBase from matplotlib.backend_bases import NavigationToolbar2, cursors, TimerBase from matplotlib.backend_bases import ShowBase, ToolbarBase, NavigationBase -from matplotlib.backend_tools import SaveFigureBase, ConfigureSubplotsBase +from matplotlib.backend_tools import SaveFigureBase, ConfigureSubplotsBase, tools from matplotlib._pylab_helpers import Gcf from matplotlib.figure import Figure @@ -538,6 +538,8 @@ def __init__(self, canvas, num, window): self.toolbar = self._get_toolbar() self.navigation = self._get_navigation() + if matplotlib.rcParams['toolbar'] == 'navigation': + self.navigation.add_tools(tools) if self.toolbar is not None: self.toolbar.update()