Python:将Matplotlib图形添加到wxFormBuilder自动生成的帧输出中?
学习Python(作为一名强大的C#程序员进入Python),对SciPy和Matplotlib的强大功能感到兴奋,因此我希望在面板上添加Matplotlib图。该面板位于笔记本中,其代码作为wxFormBuilder的输出生成(请参见“Main_gui.py”文件) 我遇到的问题是,我遇到了一个错误,在尝试了多次代码扰动后,错误仍然存在:Python:将Matplotlib图形添加到wxFormBuilder自动生成的帧输出中?,python,matplotlib,wxpython,wxformbuilder,Python,Matplotlib,Wxpython,Wxformbuilder,学习Python(作为一名强大的C#程序员进入Python),对SciPy和Matplotlib的强大功能感到兴奋,因此我希望在面板上添加Matplotlib图。该面板位于笔记本中,其代码作为wxFormBuilder的输出生成(请参见“Main_gui.py”文件) 我遇到的问题是,我遇到了一个错误,在尝试了多次代码扰动后,错误仍然存在: AttributeError:type对象“MainForm”没有属性“page\u Data” 这是我的文件: “Main.py”: “Main_g
AttributeError:type对象“MainForm”没有属性“page\u Data”
这是我的文件:
“Main.py”:
“Main_gui.py”:
回溯:
Traceback (most recent call last):
File "<project location>\Main.py", line 56, in <module>
MainApp(None).Show()
File "<project location>\Main.py", line 27, in __init__
self.plotpanel = CreatePlot(self.plot_container)
File "<project location>\Main.py", line 47, in __init__
Main_gui.MainForm.page_Data.SetSizer(sizer)
AttributeError: type object 'MainForm' has no attribute 'page_Data'
19:12:12: Debug: ..\..\include\wx/msw/private.h(697): 'UnregisterClass' failed with error 0x00000584 (class still has open windows.).
看起来在CreatePlot类中,您正在进行调用,并在其末尾执行类调用
Main_gui.MainForm.page_Data.SetSizer(sizer)
Main_gui.MainForm.page_Data.Fit()
这些需要是访问这些方法的实例调用
我想你可能希望他们是
parent.page_Data.SetSizer(sizer)
parent.page_Data.Fit()
看起来好多了-同时对FigureCanvas()行进行了更改,并更改了大小,我现在进入程序,并在面板中显示了一个图表-谢谢!现在,我只需要它来填充整个面板,确实如此,但只有在我调整框架大小之后——它必须引起某种重新绘制事件,但是parent.Fit(),其中parent是感兴趣的wx.panel,似乎不起作用。是否有可以抛出的命令来调整特定或全部尺寸大小?Fit用于使其大小适合其子窗口。使用parent.Layout()使大小调整器重新计算。
class MainApp( Main_gui.MainForm ):
# === INITIALIZATION =================================================================================
def __init__(self, parent):
#Initialize the main form
Main_gui.MainForm.__init__( self, parent )
#Create chart
self.sizer = self.page_Data.GetSizer()
self.plot_container = self.page_Data
self.plotpanel = CreatePlot(self.plot_container)
class CreatePlot(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, -1)
self.figure = Figure(figsize=(5,4), dpi=100)
self.axes = self.figure.add_subplot(111)
t = arange(0.0,3.0,0.01)
s = sin(2*pi*t)
self.axes.plot(t,s)
self.canvas = FigureCanvas(parent, -1, self.figure)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.canvas, 1, wx.TOP | wx.LEFT | wx.EXPAND)
parent.SetSizer(sizer)
parent.Fit()
Main_gui.MainForm.page_Data.SetSizer(sizer)
Main_gui.MainForm.page_Data.Fit()
parent.page_Data.SetSizer(sizer)
parent.page_Data.Fit()