From e6c47bac4e44abd983da931b8ad5cf9d9af2c7dc Mon Sep 17 00:00:00 2001 From: DBras Date: Mon, 10 Jun 2024 14:54:10 +0200 Subject: [PATCH] dev: plotting file without fluff --- plotter.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 plotter.py diff --git a/plotter.py b/plotter.py new file mode 100755 index 0000000..88275c4 --- /dev/null +++ b/plotter.py @@ -0,0 +1,28 @@ +#!./venv/bin/python3 +import pandas as pd +import json +import matplotlib.pyplot as plt +import os + +DATA_MEAS_DIR = 'data/measurements' +SPECIFIC_FILE = '' +MEAS_LOG_FILE = sorted(os.listdir(DATA_MEAS_DIR))[-1] if not SPECIFIC_FILE else SPECIFIC_FILE + +with open(os.path.join(DATA_MEAS_DIR, MEAS_LOG_FILE)) as f: + meas_data = [json.loads(line) for line in f] +data = meas_data + +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, ax2 = plt.subplot(211), plt.subplot(212) +df_resampled[[c for c in df_resampled.columns if '_p' in c]].plot(marker='.', ax=ax1, linewidth=3) +df_resampled[[c for c in df_resampled.columns if '_q' in c]].plot(marker='.', ax=ax2, linewidth=3) +plt.show(block=True)