From fb7b4e7d917286d43c7d9d31cc501a9ab47299d4 Mon Sep 17 00:00:00 2001 From: Arnaud Watlet <arnaud.watlet@umons.ac.be> Date: Wed, 7 Jun 2023 09:09:40 +0200 Subject: [PATCH] fixes plots in real_time --- plots.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/plots.py b/plots.py index e408e157..9dce967c 100644 --- a/plots.py +++ b/plots.py @@ -14,6 +14,9 @@ def plot_fulldata(fulldata, axes=None, fig=None, save=False, output="fulldata.pn ax1.set_ylabel('Current (mA)') ax1.set_title('Current') line2, = ax2.plot(fulldata[:, 2], fulldata[:, 1], '.-', label='Voltage [mV]',alpha=.5) + if plot_ads: + line3, = ax2.plot(fulldata[:, 2], fulldata[:, 3], '.-', label='Voltage U0 [mV]', alpha=.5) + line4, = ax2.plot(fulldata[:, 2], fulldata[:, 4], '.-', label='Voltage U2 [mV]', alpha=.5) ax2.set_xlabel('Time (s)') ax2.set_ylabel('Voltage (mV)') ax2.set_title('Voltage') @@ -30,21 +33,29 @@ def plot_fulldata(fulldata, axes=None, fig=None, save=False, output="fulldata.pn if realtime: fig.canvas.draw() fig.canvas.flush_events() - return fig, (ax1,ax2), (line1,line2) + if plot_ads: + return fig, (ax1,ax2), (line1,line2) + else: + return fig, (ax1, ax2), (line1, line2, line3, line4) else: return fig, (ax1, ax2) def update_realtime_fulldata_plot(last_measurement, acquired_dataset, lines, axes, fig, x_window=10, plot_ads=False): - (line1, line2) = lines (ax1,ax2) = axes t = np.append(acquired_dataset[:,2], last_measurement[:, 2][~np.isnan(last_measurement[:, 2])] + acquired_dataset[:,2][-1]) i_rt = np.append(acquired_dataset[:,0], last_measurement[:, 0][~np.isnan(last_measurement[:, 2])]) u_rt = np.append(acquired_dataset[:,1], last_measurement[:, 1][~np.isnan(last_measurement[:, 2])]) - line1.set_ydata(i_rt) - line1.set_xdata(t) - line2.set_ydata(u_rt) - line2.set_xdata(t) + lines[0].set_ydata(i_rt) + lines[0].set_xdata(t) + lines[1].set_ydata(u_rt) + lines[1].set_xdata(t) + if plot_ads: + lines[2].set_ydata(u_rt) + lines[2].set_xdata(t) + lines[3].set_ydata(u_rt) + lines[3].set_xdata(t) + ax1.relim() ax2.relim() ax1.autoscale_view(scalex=False) @@ -55,4 +66,4 @@ def update_realtime_fulldata_plot(last_measurement, acquired_dataset, lines, axe fig.canvas.draw() fig.canvas.flush_events() - return fig,(ax1,ax2), (line1,line2), np.array([i_rt,u_rt,t]).T \ No newline at end of file + return fig,(ax1,ax2), lines, np.array([i_rt,u_rt,t]).T \ No newline at end of file -- GitLab