我正在编写一个wxPython应用程序,该程序将从National DAQ读取一秒的样本,使用wxmplot lib绘制它们,并在不被操作员停止的情况下循环。 x轴是一个时间戳数组,从第一个采样的日期和时间到最后一个采样的日期和时间之间以1 /获取频率的步长进行滚动。
使用wxmplot“ plot”函数可以绘制初始图。但是,当尝试使用同一库中的update_line函数更新跟踪时(比使用另一个“绘图”函数重绘要快得多)时,我收到“ ValueError:4239463年超出范围”错误-即使使用相同的数据集。这个update_line如何运作?
我确实成功地使用了update_line函数,并将样本编号作为x轴。我首先尝试使用datetime.datetime格式,但是在这种情况下,plot()函数不知道如何处理它,因此我不得不切换到时间戳。
chan_1_line = 1 # this is trace number 1 on plot
num_samples = 4096 # acquisition frequency in Hz (number of samples per sec)
# Open the DAQ channel
task.ai_channels.add_ai_accel_chan(cDAQDevice, sensitivity=sensor_sensitivity, max_val=0.05,min_val=-0.05)
task.timing.cfg_samp_clk_timing(2048,sample_mode=AcquisitionType.CONTINUOUS)
# The first measure draws the plot, then we open a while loop with plot updates (update_line function)
# dating the samples: we get the time just before starting... (converting to float)
acq_start_time = datetime.now()
acq_start_time = acq_start_time.timestamp()
# then we acquire 1 sec. of samples (4096 samples) and convert it to an array:
sample_data = np.asarray(task.read(number_of_samples_per_channel=num_samples, timeout=4.0))
# then get time at the end of acquisition.
acq_stop_time = datetime.now()
acq_stop_time = acq_stop_time.timestamp()
# calculating the time interval between each sample
time_interval = (acq_stop_time - acq_start_time) / num_samples
# constructing an array with the sample times
time_x = np.asarray([acq_start_time + time_interval * x for x in range(0, num_samples)])
# Then create time graph with plot function (this works)
self.plotTimePanel.plot(time_x, sample_data, linewidth=1, labelfontsize=5,
use_dates=True)
# Trying to update trace 1 with the same set of data (this doesn't work)
self.plotTimePanel.update_line(chan_1_line, time_x, sample_data, draw=True)
使用相同的数据集和相同的参数,plot()函数运行良好,并且update_line()函数返回“ ValueError:4239463年超出范围”并停止。我有点被这个错误困扰...如果有人可以帮助我,我将非常感谢!