diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 37d7d276ea93..7a434d5b22ad 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -3245,6 +3245,11 @@ def _update_view(self): ax._set_position(pos_active, 'active') self.canvas.draw_idle() + def configure_subplots(self, *args): + from matplotlib import pyplot as plt + tool = plt.subplot_tool(self.canvas.figure) + tool.figure.canvas.manager.show() + def save_figure(self, *args): """Save the current figure.""" raise NotImplementedError diff --git a/lib/matplotlib/backends/_backend_tk.py b/lib/matplotlib/backends/_backend_tk.py index bc31d31e699b..3209d7db7ae4 100644 --- a/lib/matplotlib/backends/_backend_tk.py +++ b/lib/matplotlib/backends/_backend_tk.py @@ -583,16 +583,6 @@ def _Spacer(self): s.pack(side=tk.LEFT, padx=5) return s - def configure_subplots(self): - toolfig = Figure(figsize=(6, 3)) - window = tk.Toplevel() - canvas = type(self.canvas)(toolfig, master=window) - toolfig.subplots_adjust(top=0.9) - canvas.tool = SubplotTool(self.canvas.figure, toolfig) - canvas.draw() - canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1) - window.grab_set() - def save_figure(self, *args): filetypes = self.canvas.get_supported_filetypes().copy() default_filetype = self.canvas.get_default_filetype() diff --git a/lib/matplotlib/backends/backend_gtk3.py b/lib/matplotlib/backends/backend_gtk3.py index 62eb324ebce1..a1a1c6544e25 100644 --- a/lib/matplotlib/backends/backend_gtk3.py +++ b/lib/matplotlib/backends/backend_gtk3.py @@ -587,34 +587,6 @@ def on_notify_filter(*args): except Exception as e: error_msg_gtk(str(e), parent=self) - def configure_subplots(self, button): - toolfig = Figure(figsize=(6, 3)) - canvas = type(self.canvas)(toolfig) - toolfig.subplots_adjust(top=0.9) - # Need to keep a reference to the tool. - _tool = SubplotTool(self.canvas.figure, toolfig) - - w = int(toolfig.bbox.width) - h = int(toolfig.bbox.height) - - window = Gtk.Window() - try: - window.set_icon_from_file(window_icon) - except Exception: - # we presumably already logged a message on the - # failure of the main plot, don't keep reporting - pass - window.set_title("Subplot Configuration Tool") - window.set_default_size(w, h) - vbox = Gtk.Box() - vbox.set_property("orientation", Gtk.Orientation.VERTICAL) - window.add(vbox) - vbox.show() - - canvas.show() - vbox.pack_start(canvas, True, True, 0) - window.show() - def set_history_buttons(self): can_backward = self._nav_stack._pos > 0 can_forward = self._nav_stack._pos < len(self._nav_stack._elements) - 1 diff --git a/lib/matplotlib/backends/backend_wx.py b/lib/matplotlib/backends/backend_wx.py index f1887a886576..099ae5e6fe11 100644 --- a/lib/matplotlib/backends/backend_wx.py +++ b/lib/matplotlib/backends/backend_wx.py @@ -1186,26 +1186,6 @@ def pan(self, *args): self.ToggleTool(self.wx_ids['Zoom'], False) NavigationToolbar2.pan(self, *args) - def configure_subplots(self, *args): - global FigureManager # placates pyflakes: created by @_Backend.export - frame = wx.Frame(None, -1, "Configure subplots") - _set_frame_icon(frame) - - toolfig = Figure((6, 3)) - canvas = type(self.canvas)(frame, -1, toolfig) - - # Create a figure manager to manage things - FigureManager(canvas, 1, frame) - - # Now put all into a sizer - sizer = wx.BoxSizer(wx.VERTICAL) - # This way of adding to sizer allows resizing - sizer.Add(canvas, 1, wx.LEFT | wx.TOP | wx.GROW) - frame.SetSizer(sizer) - frame.Fit() - SubplotTool(self.canvas.figure, toolfig) - frame.Show() - def save_figure(self, *args): # Fetch the required filename and file type. filetypes, exts, filter_index = self.canvas._get_imagesave_wildcards() diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 1314f055ec5d..3e9088073cb9 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -1453,19 +1453,19 @@ def subplot_tool(targetfig=None): """ Launch a subplot tool window for a figure. - A :class:`matplotlib.widgets.SubplotTool` instance is returned. + A `matplotlib.widgets.SubplotTool` instance is returned. """ if targetfig is None: targetfig = gcf() - - with rc_context({'toolbar': 'None'}): # No nav toolbar for the toolfig. - toolfig = figure(figsize=(6, 3)) - toolfig.subplots_adjust(top=0.9) - - if hasattr(targetfig.canvas, "manager"): # Restore the current figure. - _pylab_helpers.Gcf.set_active(targetfig.canvas.manager) - - return SubplotTool(targetfig, toolfig) + with rc_context({"toolbar": "none"}): # No navbar for the toolfig. + # Use new_figure_manager() instead of figure() so that the figure + # doesn't get registered with pyplot. + manager = new_figure_manager(-1, (6, 3)) + manager.set_window_title("Subplot configuration tool") + tool_fig = manager.canvas.figure + tool_fig.subplots_adjust(top=0.9) + manager.show() + return SubplotTool(targetfig, tool_fig) # After deprecation elapses, this can be autogenerated by boilerplate.py. diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index ba0168e48a17..8c95ebd38179 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -1099,6 +1099,7 @@ def __init__(self, targetfig, toolfig): The figure instance to embed the subplot tool into. """ + self.figure = toolfig self.targetfig = targetfig toolfig.subplots_adjust(left=0.2, right=0.9) toolfig.suptitle("Click on slider to adjust subplot param")