From b10d5f623e45b97ac7a69d26ebe4edd1233f4844 Mon Sep 17 00:00:00 2001 From: DBras Date: Mon, 10 Jun 2024 13:49:08 +0200 Subject: [PATCH] question: D3 Q2 --- demo_plotter.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/demo_plotter.py b/demo_plotter.py index 991152b..de1e8dc 100755 --- a/demo_plotter.py +++ b/demo_plotter.py @@ -36,18 +36,22 @@ else: ################################################################################ -################## Question 1 ################################################## +################## Question 2 ################################################## ################################################################################ # Construct a dataframe and pivot it to obtain a dataframe with a column per unit, and a row per timestamp. df = pd.DataFrame.from_records(data) +df['time'] = pd.to_datetime(df['time'], unit='s') df_pivot = df.pivot_table(values='value', columns='unit', index='time') +df_resampled = df_pivot.resample('s').mean() +df_resampled.interpolate(method='linear', inplace=True) +df_resampled = pd.DataFrame(df_resampled) # Plot the data. Note, that the data will mostly not be plotted with lines. plt.ion() # Turn interactive mode on plt.figure() ax1 = plt.subplot(211) # Make two separate figures ax2 = plt.subplot(212) -df_pivot['pcc_p'].plot(marker='.', ax=ax1, linewidth=3) -df_pivot['pcc_q'].plot(marker='.', ax=ax1, linewidth=3) +df_resampled[[c for c in df_resampled.columns if c.endswith('_p')]].plot(marker='.', ax=ax1, linewidth=3) +df_resampled[[c for c in df_resampled.columns if c.endswith('_q')]].plot(marker='.', ax=ax2, linewidth=3) plt.show(block=True)