@@ -898,37 +898,25 @@ def __init__(self, num, fig, *, canvas_class=None):
898898 "required after the deprecation period starting in Matplotlib "
899899 "%(since)s elapses." )
900900 self .canvas = self .get_canvas (fig )
901- w , h = map (math .ceil , fig .bbox .size )
902- self .canvas .SetInitialSize (wx .Size (w , h ))
903- self .canvas .SetFocus ()
904- self .sizer = wx .BoxSizer (wx .VERTICAL )
905- self .sizer .Add (self .canvas , 1 , wx .TOP | wx .LEFT | wx .EXPAND )
906- # By adding toolbar in sizer, we are able to put it at the bottom
907- # of the frame - so appearance is closer to GTK version
908901
909902 self .figmgr = FigureManagerWx (self .canvas , num , self )
910903
911904 self .toolbar = self ._get_toolbar ()
912-
913905 if self .figmgr .toolmanager :
914906 backend_tools .add_tools_to_manager (self .figmgr .toolmanager )
915907 if self .toolbar :
916908 backend_tools .add_tools_to_container (self .toolbar )
917-
918909 if self .toolbar is not None :
919- self .toolbar .Realize ()
920- # On Windows platform, default window size is incorrect, so set
921- # toolbar width to figure width.
922- tw , th = self .toolbar .GetSize ()
923- fw , fh = self .canvas .GetSize ()
924- # By adding toolbar in sizer, we are able to put it at the bottom
925- # of the frame - so appearance is closer to GTK version.
926- self .toolbar .SetSize (wx .Size (fw , th ))
927- self .sizer .Add (self .toolbar , 0 , wx .LEFT | wx .EXPAND )
928- self .SetSizer (self .sizer )
929- self .Fit ()
910+ self .SetToolBar (self .toolbar )
930911
912+ # On Windows, canvas sizing must occur after toolbar addition;
913+ # otherwise the toolbar further resizes the canvas.
914+ w , h = map (math .ceil , fig .bbox .size )
915+ self .canvas .SetInitialSize (wx .Size (w , h ))
931916 self .canvas .SetMinSize ((2 , 2 ))
917+ self .canvas .SetFocus ()
918+
919+ self .Fit ()
932920
933921 self .Bind (wx .EVT_CLOSE , self ._on_close )
934922
@@ -966,10 +954,6 @@ def _on_close(self, event):
966954 # Carry on with close event propagation, frame & children destruction
967955 event .Skip ()
968956
969- def GetToolBar (self ):
970- """Override wxFrame::GetToolBar as we don't have managed toolbar"""
971- return self .toolbar
972-
973957 def Destroy (self , * args , ** kwargs ):
974958 try :
975959 self .canvas .mpl_disconnect (self .toolbar ._id_drag )
@@ -1049,9 +1033,9 @@ def set_window_title(self, title):
10491033
10501034 def resize (self , width , height ):
10511035 # docstring inherited
1052- self . canvas . SetInitialSize (
1053- wx . Size ( math . ceil ( width ), math . ceil ( height )))
1054- self . window . GetSizer (). Fit ( self . window )
1036+ # Directly using SetClientSize doesn't handle the toolbar on Windows.
1037+ self . window . SetSize ( self . window . ClientToWindowSize ( wx . Size (
1038+ math . ceil ( width ), math . ceil ( height ))) )
10551039
10561040
10571041def _load_bitmap (filename ):
@@ -1073,8 +1057,8 @@ def _set_frame_icon(frame):
10731057
10741058
10751059class NavigationToolbar2Wx (NavigationToolbar2 , wx .ToolBar ):
1076- def __init__ (self , canvas , coordinates = True ):
1077- wx .ToolBar .__init__ (self , canvas .GetParent (), - 1 )
1060+ def __init__ (self , canvas , coordinates = True , * , style = wx . TB_BOTTOM ):
1061+ wx .ToolBar .__init__ (self , canvas .GetParent (), - 1 , style = style )
10781062
10791063 if 'wxMac' in wx .PlatformInfo :
10801064 self .SetToolBitmapSize ((24 , 24 ))
@@ -1206,7 +1190,7 @@ def set_history_buttons(self):
12061190# tools for matplotlib.backend_managers.ToolManager:
12071191
12081192class ToolbarWx (ToolContainerBase , wx .ToolBar ):
1209- def __init__ (self , toolmanager , parent , style = wx .TB_HORIZONTAL ):
1193+ def __init__ (self , toolmanager , parent , style = wx .TB_BOTTOM ):
12101194 ToolContainerBase .__init__ (self , toolmanager )
12111195 wx .ToolBar .__init__ (self , parent , - 1 , style = style )
12121196 self ._space = self .AddStretchableSpace ()
0 commit comments