Skip to content

Dedupe implementations of configure_subplots(). #16818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions lib/matplotlib/backends/_backend_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
28 changes: 0 additions & 28 deletions lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 0 additions & 20 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 10 additions & 10 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Member

Choose a reason for hiding this comment

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

The work around there is to put the show on a 0s timer on the event loop. That will make it show as soon as the event loop is allowed to run again (which is either on return of control to the user or when plt.show() is called).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you want to put in that patch? given that you seem to know what to do...

return SubplotTool(targetfig, tool_fig)


# After deprecation elapses, this can be autogenerated by boilerplate.py.
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down