更新wxmplot图表时出错

2024-04-25 07:11:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在python3.6中创建一个使用wxmplot动态更新的图形。根据这里的文档:http://cars.uchicago.edu/software/python/wxmplot/plotpanel.html#plotpanel.plot,我应该调用update_line函数,与重画绘图相比,该函数允许更快的图形更新。但是,这个功能不适合我。这是我的代码:

    import wx
    import random
    from wxmplot import PlotPanel

    class MainFrame(wx.Frame):
        def __init__(self, parent):
            wx.Frame.__init__(self, None, size=(1200, 900))

            self.panel_1 = Panel_one(self)
            self.button_1 = wx.Button(self, label='update graph', size=(100, 30))
            self.Bind(wx.EVT_BUTTON, self.click_button, self.button_1)
            sizer = wx.BoxSizer(wx.HORIZONTAL)
            sizer.Add(self.panel_1, 0, wx.LEFT, 5)
            sizer.Add(self.button_1, 0, wx.LEFT, 5)
            self.SetSizer(sizer)

        def click_button(self, e):
            x.append(max(x)+1)
            y.append(random.randint(0, 10))
            self.panel_1.graph1.update_line(max(x), x, y)

    class Panel_one(wx.Panel):
        def __init__(self, parent):
            wx.Panel.__init__(self, parent, -1, style=wx.SUNKEN_BORDER)

            self.graph1 = PlotPanel(self, size=(400, 400))
            self.graph1.plot(x, y)


    x = [0, 1, 2]
    y = [5, 8, 4]

    if __name__ == "__main__":
        app = wx.App(redirect=False)
        frame = MainFrame(None)
        frame.Show()
        app.MainLoop()

当一个新的数据被随机的点击时,新的数据被点击更新。我得到一个错误:AttributeError:'list'对象没有属性'min'。我不确定我做错了什么,但我认为这可能与update_line函数需要3条信息有关:我的x和y向量以及一条轨迹。根据我的理解,trace是需要更新的行的索引,但我不确定我是否正确地执行了此操作。有什么办法解决这个问题吗?在

编辑:

^{pr2}$

Tags: 函数importselfsizeinitdeflineupdate