From 4b710899121516a39560a3c7a27c25c7e73f68f7 Mon Sep 17 00:00:00 2001
From: Martin Killenberg <martin.killenberg@desy.de>
Date: Thu, 20 Oct 2022 18:27:19 +0200
Subject: [PATCH] factor plotting into separate function

---
 Python_script/prototype.py | 51 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 49 insertions(+), 2 deletions(-)

diff --git a/Python_script/prototype.py b/Python_script/prototype.py
index c036ccb..5e19573 100755
--- a/Python_script/prototype.py
+++ b/Python_script/prototype.py
@@ -267,7 +267,7 @@ class Measurements:
 
         return equilibrium_indicator
 
-    def plot_output(self, output_basename, show_plot_window):
+    def plot_output(self, output_basename, show_plot_window, safe_pdf = True):
         csv_data = pd.read_csv(output_basename+'.csv')
         fig, ax1 = plt.subplots(2, figsize=(12, 10))
         fig.suptitle("Graphical representation of chamber output", color="red")
@@ -321,6 +321,53 @@ class Measurements:
         return (target_hum-self.max_delta_hum <= float(readback_hum)) and \
                (float(readback_hum) <= target_hum+self.max_delta_hum)
 
+def plot_output(output_basename, show_plot_window, save_pdf=True):
+    csv_data = pd.read_csv(output_basename+'.csv')
+    fig, ax1 = plt.subplots(2, figsize=(12, 10))
+    fig.suptitle("Graphical representation of chamber output", color="red")
+
+    path_collection01 = ax1[0].scatter(csv_data.TIMESTAMP, csv_data.S21_PHASE, c='red', marker='<', label='Phase')
+    twin2_0 = ax1[0].twinx()
+    path_collection02 = twin2_0.scatter(csv_data.TIMESTAMP, csv_data.S21_MAGNITUDE, c='#3120E0', marker='4',
+                                        label='Magnitude')
+    twin3_0 = ax1[0].twinx()
+    twin3_0.spines['right'].set_position(('outward', 40))
+    path_collection03 = twin3_0.scatter(csv_data.TIMESTAMP, csv_data.EQUILIBRIUM_INDICATOR, c='black', marker=".",
+                                        label='Equilibrium_Indicator')
+    ax1[0].set_xlabel("TIMESTAMP")
+    ax1[0].set_ylabel("PHASE", color='red')
+    twin2_0.set_ylabel("MAGNITUDE", color='#3120E0')
+    twin3_0.set_ylabel("EQUILIBRIUM_INDICATOR", color='black')
+
+    ax1[0].grid(True, linestyle=":")
+    all_path_collections = [path_collection01, path_collection02, path_collection03]
+    labels = [pc.get_label() for pc in all_path_collections]
+    ax1[0].legend(all_path_collections, labels, loc='lower right')
+
+    path_collection11 = ax1[1].scatter(csv_data.TIMESTAMP, csv_data.READBACK_TEMPERATURE, c='blue', marker='p',
+                                       label="Temperature")
+    twin2_1 = ax1[1].twinx()
+    path_collection12 = twin2_1.scatter(csv_data.TIMESTAMP, csv_data.READBACK_HUMIDITY, c='green', marker="*",
+                                        label="Humidity")
+    twin3_1 = ax1[1].twinx()
+    twin3_1.spines['right'].set_position(('outward', 40))
+    path_collection13 = twin3_1.scatter(csv_data.TIMESTAMP, csv_data.EQUILIBRIUM_INDICATOR, c='black', marker=".",
+                                        label="Equilibrium_Indicator")
+    ax1[1].set_xlabel("TIMESTAMP")
+    ax1[1].set_ylabel("TEMPERATURE ", color='blue')
+    twin2_1.set_ylabel("HUMIDITY", color='green')
+    twin3_1.set_ylabel("EQUILIBRIUM_INDICATOR", color='black')
+    ax1[1].grid(True, linestyle=":")
+    all_path_collections = [path_collection11, path_collection12, path_collection13]
+    labels = [pc.get_label() for pc in all_path_collections]
+    ax1[1].legend(all_path_collections, labels, loc='lower right')
+
+    if save_pdf:
+        fig.savefig(output_basename + '_graph.pdf')
+
+    if show_plot_window:
+        plt.show()
+
 
 if __name__ == '__main__':
     parser = ArgumentParser()
@@ -362,7 +409,7 @@ if __name__ == '__main__':
     try:
 
         mes.perform_measurements()
-        mes.plot_output(output_basename, args.plot)
+        plot_output(output_basename, args.plot)
 
     finally:
         mes.chamber.close()
-- 
GitLab