From cbf974f6f82f520eda00dd06c01761eee53d9ddf Mon Sep 17 00:00:00 2001 From: juliangaal Date: Tue, 23 Apr 2019 21:29:58 +0200 Subject: [PATCH] add plotting scripts for continous data --- viz/plot.py | 59 ++++++++++++++++++++++++++++++++++++ viz/plot_rot.py | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 viz/plot.py create mode 100644 viz/plot_rot.py diff --git a/viz/plot.py b/viz/plot.py new file mode 100644 index 0000000..23fcd7e --- /dev/null +++ b/viz/plot.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 + +import sys +import numpy as np +import pandas as pd +import matplotlib.pyplot as plt + +def plot(filename: str, filename_2: str, num_data_points: int): + df_1 = pd.read_csv(filename, delimiter = ',', names=['roll', 'pitch']) + df_2 = pd.read_csv(filename_2, delimiter = ',', names=['roll', 'pitch']) + n = num_data_points + + y = df_1['roll'].to_list() + x = np.linspace(0, n, n) + plt.plot(x, y[:n], label='roll raw: var ' + str(np.var(y)), color='black') + var_1 = np.var(y) + + y = df_2['roll'].to_list() + x = np.linspace(0, n, n) + plt.plot(x, y[:n], label='roll calibrated: var ' + str(np.var(y)), color='red') + var_2 = np.var(y) + + plt.ylim([-0.1, 0.1]) + plt.legend() + plt.show() + + if var_1 < var_2: + print("Variance of {} is smaller: {}".format(filename, var_1)) + else: + print("Variance of {} is smaller: {}".format(filename_2, var_2)) + + + y = df_1['pitch'].to_list() + x = np.linspace(0, n, n) + plt.plot(x, y[:n], label='pitch raw: var ' + str(np.var(y)), color='black') + var_1 = np.var(y) + + y = df_2['pitch'].to_list() + x = np.linspace(0, n, n) + plt.plot(x, y[:n], label='pitch calibrated: var ' + str(np.var(y)), color='red') + var_2 = np.var(y) + + plt.ylim([-0.1, 0.1]) + plt.legend() + plt.show() + + if var_1 < var_2: + print("Variance of {} is smaller: {}".format(filename, var_1)) + else: + print("Variance of {} is smaller: {}".format(filename_2, var_2)) + + +file_1 = sys.argv[1] +file_1 = sys.argv[1] +file_2 = sys.argv[2] +n = int(sys.argv[3]) +plot(file_1, file_2, n) + + diff --git a/viz/plot_rot.py b/viz/plot_rot.py new file mode 100644 index 0000000..b06db96 --- /dev/null +++ b/viz/plot_rot.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 + +import sys +import numpy as np +import pandas as pd +import matplotlib.pyplot as plt + +def plot(filename: str, filename_2: str, num_data_points: int): + df_1 = pd.read_csv(filename, delimiter = ',', names=['x', 'y', 'z']) + df_2 = pd.read_csv(filename_2, delimiter = ',', names=['x', 'y', 'z']) + n = num_data_points + + y = df_1['x'].to_list() + x = np.linspace(0, n, n) + plt.plot(x, y[:n], label='x raw: var ' + str(np.var(y)), color='black') + var_1 = np.var(y) + + y = df_2['x'].to_list() + x = np.linspace(0, n, n) + plt.plot(x, y[:n], label='x calib: var ' + str(np.var(y)), color='red') + var_2 = np.var(y) + + plt.ylim([-0.1, 0.1]) + plt.legend() + plt.show() + + if var_1 < var_2: + print("Variance of {} is smaller: {}".format(filename, var_1)) + else: + print("Variance of {} is smaller: {}".format(filename_2, var_2)) + + + y = df_1['y'].to_list() + x = np.linspace(0, n, n) + plt.plot(x, y[:n], label='y raw: var ' + str(np.var(y)), color='black') + var_1 = np.var(y) + + y = df_2['y'].to_list() + x = np.linspace(0, n, n) + plt.plot(x, y[:n], label='y calib: var ' + str(np.var(y)), color='red') + var_2 = np.var(y) + + plt.ylim([-0.1, 0.1]) + plt.legend() + plt.show() + + if var_1 < var_2: + print("Variance of {} is smaller: {}".format(filename, var_1)) + else: + print("Variance of {} is smaller: {}".format(filename_2, var_2)) + + + y = df_1['z'].to_list() + x = np.linspace(0, n, n) + plt.plot(x, y[:n], label='z raw: var ' + str(np.var(y)), color='black') + var_1 = np.var(y) + + y = df_2['z'].to_list() + x = np.linspace(0, n, n) + plt.plot(x, y[:n], label='z calib: var ' + str(np.var(y)), color='red') + var_2 = np.var(y) + + plt.ylim([-0.1, 0.1]) + plt.legend() + plt.show() + + if var_1 < var_2: + print("Variance of {} is smaller: {}".format(filename, var_1)) + else: + print("Variance of {} is smaller: {}".format(filename_2, var_2)) + + +file_1 = sys.argv[1] +file_1 = sys.argv[1] +file_1 = sys.argv[1] +file_2 = sys.argv[2] +n = int(sys.argv[3]) +plot(file_1, file_2, n) + +