Добро пожаловать в переполнение стека.
Во-первых, ваш код немного усложнен.Нет необходимости использовать так много классов.
Во-вторых, если вы планируете использовать matplotlib с библиотекой GUI, вам нужно импортировать бэкэнд, чтобы matplotlib прекрасно работал в приложении, которое вы пишете.
Относительно того, почему панель сжимается.Я не совсем уверен.Возможно ошибка, когда matplotlib пытается построить без подходящего бэкэнда.
Я упростил ваш код и добавил к нему некоторые комментарии.
import wx
import numpy as np
import matplotlib as mpl
## Import the matplotlib backend for wxPython
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
## Only one class is really needed in this case. There is no need to have
## a class for the App, a class for the frame and a class for the panel
class MyWin(wx.Frame):
def __init__(self, title, pos):
super().__init__(parent=None, title=title, pos=pos)
self.panel = wx.Panel(parent=self)
self.button = wx.Button(parent=self.panel, label='Create plot', pos=(20, 80))
self.button.Bind(wx.EVT_BUTTON, self.onSubmit)
def onSubmit(self, event):
x = np.arange(10)
y = np.arange(10)
## This is to work with matplotlib inside wxPython
## I prefer to use the object oriented API
self.figure = mpl.figure.Figure(figsize=(5, 5))
self.axes = self.figure.add_subplot(111)
self.canvas = FigureCanvas(self, -1, self.figure)
## This is to avoid showing the plot area. When set to True
## clicking the button show the canvas and the canvas covers the button
## since the canvas is placed by default in the top left corner of the window
self.canvas.Show(False)
self.axes.plot(x, y)
self.figure.savefig('Figure.png', bbox_inches='tight', facecolor='None')
if __name__ == '__main__':
app = wx.App()
win = MyWin('My Frame', (100, 100))
win.Show()
app.MainLoop()
Надеюсь, это поможет.