Как обновить график wxmplot с метками времени в качестве оси X? - PullRequest
0 голосов
/ 25 января 2019

Я пишу приложение wxPython, которое считывает одну секунду сэмплов из DAQ National Instruments, строит их график с использованием wxmplot lib и выполняет циклы, пока не остановлен оператором.Ось X - это массив меток времени, идущий от даты и времени первой выборки к дате и времени последней выборки с шагом 1 / частота сбора данных.

У меня нет проблем, чтобы нарисовать начальный график с использованием wxmplotфункция "сюжет".Но при попытке обновить трассировку с помощью функции update_line из той же библиотеки (намного быстрее, чем перерисовка с помощью другой функции plot), я получаю ошибку «ValueError: year 4239463 Out of Range» - даже с тем же набором данных,Как работает этот 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 находится вне диапазона» и останавливается.Я вроде застрял с этой ошибкой ... Если кто-нибудь может помочь, я был бы очень благодарен!

...