Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit42ffab0

Browse files
committed
Dedupe implementations of configure_subplot().
Rely on pyplot auto-backend-detection to pop up a window with thecorrect canvas class (technically this means one can end up witha gtk3agg subplot tool when the main figure is gtk3cairo, but thatshouldn't be a real problem...).- Qt is excluded because it has its own (native) subplot config tool.- wx needs to restore a call to Destroy() because the subplot config figure is not pyplot-managed, so `Gcf.destroy(self.num)` is a noop.- Add a reference to the subplot config figure from the subplot tool widget.
1 parenta57ea3d commit42ffab0

File tree

6 files changed

+16
-68
lines changed

6 files changed

+16
-68
lines changed

‎lib/matplotlib/backend_bases.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3138,6 +3138,11 @@ def _update_view(self):
31383138
ax._set_position(pos_active,'active')
31393139
self.canvas.draw_idle()
31403140

3141+
defconfigure_subplots(self,*args):
3142+
frommatplotlibimportpyplotasplt
3143+
tool=plt.subplot_tool(self.canvas.figure)
3144+
tool.figure.canvas.manager.show()
3145+
31413146
defsave_figure(self,*args):
31423147
"""Save the current figure."""
31433148
raiseNotImplementedError

‎lib/matplotlib/backends/_backend_tk.py‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -571,16 +571,6 @@ def _Spacer(self):
571571
s.pack(side=tk.LEFT,padx=5)
572572
returns
573573

574-
defconfigure_subplots(self):
575-
toolfig=Figure(figsize=(6,3))
576-
window=tk.Toplevel()
577-
canvas=type(self.canvas)(toolfig,master=window)
578-
toolfig.subplots_adjust(top=0.9)
579-
canvas.tool=SubplotTool(self.canvas.figure,toolfig)
580-
canvas.draw()
581-
canvas.get_tk_widget().pack(side=tk.TOP,fill=tk.BOTH,expand=1)
582-
window.grab_set()
583-
584574
defsave_figure(self,*args):
585575
filetypes=self.canvas.get_supported_filetypes().copy()
586576
default_filetype=self.canvas.get_default_filetype()

‎lib/matplotlib/backends/backend_gtk3.py‎

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -580,34 +580,6 @@ def on_notify_filter(*args):
580580
exceptExceptionase:
581581
error_msg_gtk(str(e),parent=self)
582582

583-
defconfigure_subplots(self,button):
584-
toolfig=Figure(figsize=(6,3))
585-
canvas=type(self.canvas)(toolfig)
586-
toolfig.subplots_adjust(top=0.9)
587-
# Need to keep a reference to the tool.
588-
_tool=SubplotTool(self.canvas.figure,toolfig)
589-
590-
w=int(toolfig.bbox.width)
591-
h=int(toolfig.bbox.height)
592-
593-
window=Gtk.Window()
594-
try:
595-
window.set_icon_from_file(window_icon)
596-
exceptException:
597-
# we presumably already logged a message on the
598-
# failure of the main plot, don't keep reporting
599-
pass
600-
window.set_title("Subplot Configuration Tool")
601-
window.set_default_size(w,h)
602-
vbox=Gtk.Box()
603-
vbox.set_property("orientation",Gtk.Orientation.VERTICAL)
604-
window.add(vbox)
605-
vbox.show()
606-
607-
canvas.show()
608-
vbox.pack_start(canvas,True,True,0)
609-
window.show()
610-
611583
defset_history_buttons(self):
612584
can_backward=self._nav_stack._pos>0
613585
can_forward=self._nav_stack._pos<len(self._nav_stack._elements)-1

‎lib/matplotlib/backends/backend_wx.py‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,26 +1152,6 @@ def pan(self, *args):
11521152
self.ToggleTool(self.wx_ids['Zoom'],False)
11531153
NavigationToolbar2.pan(self,*args)
11541154

1155-
defconfigure_subplots(self,*args):
1156-
globalFigureManager# placates pyflakes: created by @_Backend.export
1157-
frame=wx.Frame(None,-1,"Configure subplots")
1158-
_set_frame_icon(frame)
1159-
1160-
toolfig=Figure((6,3))
1161-
canvas=type(self.canvas)(frame,-1,toolfig)
1162-
1163-
# Create a figure manager to manage things
1164-
FigureManager(canvas,1,frame)
1165-
1166-
# Now put all into a sizer
1167-
sizer=wx.BoxSizer(wx.VERTICAL)
1168-
# This way of adding to sizer allows resizing
1169-
sizer.Add(canvas,1,wx.LEFT|wx.TOP|wx.GROW)
1170-
frame.SetSizer(sizer)
1171-
frame.Fit()
1172-
SubplotTool(self.canvas.figure,toolfig)
1173-
frame.Show()
1174-
11751155
defsave_figure(self,*args):
11761156
# Fetch the required filename and file type.
11771157
filetypes,exts,filter_index=self.canvas._get_imagesave_wildcards()

‎lib/matplotlib/pyplot.py‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,19 +1311,19 @@ def subplot_tool(targetfig=None):
13111311
"""
13121312
Launch a subplot tool window for a figure.
13131313
1314-
A:class:`matplotlib.widgets.SubplotTool` instance is returned.
1314+
A `matplotlib.widgets.SubplotTool` instance is returned.
13151315
"""
13161316
iftargetfigisNone:
13171317
targetfig=gcf()
1318-
1319-
withrc_context({'toolbar':'None'}):#No nav toolbar forthetoolfig.
1320-
toolfig=figure(figsize=(6,3))
1321-
toolfig.subplots_adjust(top=0.9)
1322-
1323-
ifhasattr(targetfig.canvas,"manager"):# Restore the current figure.
1324-
_pylab_helpers.Gcf.set_active(targetfig.canvas.manager)
1325-
1326-
returnSubplotTool(targetfig,toolfig)
1318+
withrc_context({"toolbar":"none"}):# No navbar for the toolfig.
1319+
#Use new_figure_manager() instead of figure() so thatthefigure
1320+
# doesn't get registered with pyplot.
1321+
manager=new_figure_manager(-1, (6,3))
1322+
manager.set_window_title("Subplot configuration tool")
1323+
tool_fig=manager.canvas.figure
1324+
tool_fig.subplots_adjust(top=0.9)
1325+
manager.show()
1326+
returnSubplotTool(targetfig,tool_fig)
13271327

13281328

13291329
# After deprecation elapses, this can be autogenerated by boilerplate.py.

‎lib/matplotlib/widgets.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,7 @@ def __init__(self, targetfig, toolfig):
10991099
The figure instance to embed the subplot tool into.
11001100
"""
11011101

1102+
self.figure=toolfig
11021103
self.targetfig=targetfig
11031104
toolfig.subplots_adjust(left=0.2,right=0.9)
11041105
toolfig.suptitle("Click on slider to adjust subplot param")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp