0

こんにちは、私は Arduino からデータを読み込んで処理しています。このコードを使用して、データをライブでプロットしようとしています。このコードを編集して、入ってくる 2 つのデータ セットで動作するようにしました。データ セットごとに 1 行が必要です。このコードを機能させるために多くのことを試みましたが、今のところこれで行き詰まっています。[100,110] を使用してデータをテストしていますが、コードを実行すると

IndexError                                Traceback (most recent call last)
/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/IPython/utils/py3compat.py in execfile(fname, *where)
173             else:
174                 filename = fname
--> 175             __builtin__.execfile(filename, *where)

/Users/Tyler/Desktop/Arduino/Graphing_22.py in <module>()
304 if __name__ == '__main__':
305     app = wx.PySimpleApp()
--> 306     app.frame = GraphFrame()
307     app.frame.Show()
308     app.MainLoop()

 /Users/Tyler/Desktop/Arduino/Graphing_22.py in __init__(self)
 87         self.create_menu()
 88         self.create_status_bar() 
 ---> 89         self.create_main_panel()
 90 
 91         self.redraw_timer = wx.Timer(self)

/Users/Tyler/Desktop/Arduino/Graphing_22.py in create_main_panel(self)
109         self.panel = wx.Panel(self)
110 
--> 111         self.init_plot()
112         self.canvas = FigCanvas(self.panel, -1, self.fig)
113 

/Users/Tyler/Desktop/Arduino/Graphing_22.py in init_plot(self)
180         #adding a line to the plot

181         self.plot_data = self.axes.plot(
--> 182                                        self.data[1],
183                                        linewidth=1,
184                                        color=(1, 2, 0),

IndexError: list index out of range

このコードは非常に長いので、関連すると思われるものを投稿します。他に何か必要な場合はお知らせください。助けてくれてありがとう。

def __init__(self):
    wx.Frame.__init__(self, None, -1, self.title)

    self.datagen = DataGen()
    self.data = [self.datagen.next()]
    #splitting data at '
    #self.data = [self.datagen.next().split(",")
    self.paused = False


    self.create_menu()
    self.create_status_bar()
    self.create_main_panel()

    self.redraw_timer = wx.Timer(self)
    self.Bind(wx.EVT_TIMER, self.on_redraw_timer, self.redraw_timer)        
    self.redraw_timer.Start(REFRESH_INTERVAL_MS)

def init_plot(self):
    self.dpi = 100
    self.fig = Figure((3.0, 3.0), dpi=self.dpi)

    self.axes = self.fig.add_subplot(111)
    self.axes.set_axis_bgcolor('black')
    self.axes.set_title('Arduino Serial Data', size=12)

    pylab.setp(self.axes.get_xticklabels(), fontsize=8)
    pylab.setp(self.axes.get_yticklabels(), fontsize=8)

    # plot the data as a line series, and save the reference 
    # to the plotted line series
    #
    self.plot_data = self.axes.plot(
                                    self.data[0], 
                                    linewidth=1,
                                    color=(1, 1, 0),
                                    )[0]

    #adding a line to the plot
    self.plot_data = self.axes.plot(
                                   self.data[1],
                                   linewidth=1,
                                   color=(1, 2, 0),
                                    )[1]
4

1 に答える 1