使用matplotlib的wxpython不会初始化

时间:2013-12-12 04:13:04

标签: python matplotlib wxpython

我尝试在matplotlib中使用wxpython,但存在一些问题。

import wx
from matplotlib.figure import Figure
import numpy as np
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas

class MplCanvasFrame(wx.Frame):
    def _init_(self,parent):
        wx.Frame._init_(self, parent, size=(600, 400),
                        title='Matplotlib Figure with Navigation Toolbar')
        self.figure = Figure()

        self.axes = self.figure.add_subplot(111)

        x = np.arange(0, 6, .01)
        y = np.sin(x**2)*np.exp(-x)
        self.axes.plot(x, y)
        self.canvas = FigureCanvas(self, -1, self.figure)
app = wx.App(redirect = False)
frame = MplCanvasFrame(None)
frame.Show()
app.MainLoop()

它根本不绘制曲线。

但是当我尝试这个时:


import wx
import wx
from matplotlib.figure import Figure
import numpy as np
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas

app = wx.App()
frame = wx.Frame(None, title = 'dasf',size = (600, 400))
figure = Figure()
axes = figure.add_subplot(111)
x = np.arange(0, 6, .01)
y = np.sin(x**2)*np.exp(-x)
axes.plot(x, y)
canvas = FigureCanvas(frame, -1, figure)
frame.Show()
app.MainLoop()

绘制曲线。

为什么?

1 个答案:

答案 0 :(得分:0)

我认为问题是__init__的拼写。每边应该有两个下划线(请注意,这在代码的两个位置)。