Should it keep the exact size of 8x6 inches or the width to height ratio as 8 to 6?
If it's the former, wouldn't it work to put it in the center of a 3x3 FlexGridSizer and make all cells except the central one growable? You didn't provide a minimal reproducible example, showing what you're drawing and how, so I made my own, loosely based on the first example from here:
from numpy import arange, sin, pi
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
import wx
class MyCanvasPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, size=(800, 600))
self.figure = Figure()
self.figure.set_size_inches(8, 6)
self.axes = self.figure.add_subplot(111)
self.canvas = FigureCanvas(self, -1, self.figure)
sizer = wx.FlexGridSizer(3, 3, 0, 0)
for i in range(4): sizer.AddStretchSpacer()
sizer.Add(self.canvas, 1, wx.EXPAND)
for i in range(4): sizer.AddStretchSpacer()
sizer.AddGrowableRow(0, 1)
sizer.AddGrowableRow(2, 1)
sizer.AddGrowableCol(0, 1)
sizer.AddGrowableCol(2, 1)
self.SetSizer(sizer)
self.Fit()
def Draw(self):
t = arange(0.0, 3.0, 0.01)
s = sin(2 * pi * t)
self.axes.plot(t, s)
class MyFrame(wx.Frame):
def __init__(self, title):
wx.Frame.__init__(self, None, -1, title, size=(800, 600))
self.panel = MyCanvasPanel(self)
self.panel.Draw()
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame("8x6 inches")
self.SetTopWindow(frame)
frame.Show(True)
return True
if __name__ == "__main__" :
app = MyApp(False)
app.MainLoop()
If it's the latter - the plot should grow and shrink, but proportionally - then wouldn't it work to simply set aspect to 'equal' with matplotlib, e. g.:
class MyCanvasPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.figure = Figure()
self.axes = self.figure.add_subplot(111)
self.axes.set_aspect('equal', 'box')
self.canvas = FigureCanvas(self, -1, self.figure)
sizer = wx.BoxSizer()
sizer.Add(self.canvas, 1, wx.EXPAND)
self.SetSizer(sizer)
self.Fit()