嘿伙计们,我正在读取来自 Arduino 处理它的数据,并使用我发现的这段代码来尝试实时绘制数据。我已编辑此代码以使其与传入的两组数据一起工作,并且我希望每组数据都有一行。我已经尝试了很多方法来让这段代码正常工作,但现在这就是我卡住的地方。我正在使用 [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]