[英]Python graphing issue
Hey guys I am reading in data from an Arduino processing it and using this code I found to try and plot the data live. 大家好,我正在从Arduino处理数据中读取数据,并使用发现的这段代码尝试实时绘制数据。 I have edited this code to make it work with two sets of data coming in and I want a line for each set of data.
我已经编辑了此代码,以使其能够处理传入的两组数据,并且我希望每组数据都包含一行。 I have tried a lot of things to get this code to work but right now this is where I am stuck.
我已经尝试了很多事情来使此代码正常工作,但是现在这就是我遇到的问题。 I am testing data using [100,110] but when I run the code I get
我正在使用[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
The code is really long for this so I will post what I think is relevant. 该代码真的很长,因此我将发布我认为相关的内容。 Let me know if anything else is needed.
让我知道是否还有其他需要。 Thanks for the help.
谢谢您的帮助。
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]
The error message IndexError: list index out of range
indicates that for line 182
data[1]
is out of range - this means there is no data[1]
element (data is len 1 or len 0). 错误消息
IndexError: list index out of range
表示对于第182
行, data[1]
超出范围-这意味着没有data[1]
元素(数据为len 1或len 0)。 You need to find the line in your code where you build the data
list to understand why this is the case. 您需要在代码中找到建立
data
列表的那一行,以了解为什么会这样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.