From 3e0e769cf33d2a6fca635ea2b62fae1a91dd07e0 Mon Sep 17 00:00:00 2001
From: Michael Pawelzik <michael.pawelzik@desy.de>
Date: Thu, 27 Jul 2023 13:17:08 +0200
Subject: [PATCH] annotation string added in measurementplot module for show
 Textinfo left to subplot window for phase and magnitude

---
 Python_script/MeasurementPlot.py | 38 +++++++++++++++++++++++---------
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git a/Python_script/MeasurementPlot.py b/Python_script/MeasurementPlot.py
index 141f11f..b165615 100644
--- a/Python_script/MeasurementPlot.py
+++ b/Python_script/MeasurementPlot.py
@@ -11,17 +11,21 @@ class PlottingError(Exception):
     pass
 
 class MeasurementPlot:
-    def __init__(self, title=''):
+    def __init__(self, title='', legend_loc = 'lower right', legend_bbox_to_anchor = None):
           # set python for opening an separate plot window when starting from anaconda, Michael
         if 'ipykernel' in sys.modules:
             from IPython import get_ipython
             get_ipython().run_line_magic('matplotlib', 'qt')
         
+        # parameter for legend of subplots
+        self.legend_loc = legend_loc
+        self.legend_bbox_to_anchor = legend_bbox_to_anchor
       
         # Third, Fourth and Fifth plot for additional external sensors, Michael
         self.fig, self.ax1 = plt.subplots(5, figsize=(25, 20))
-        self.fig.subplots_adjust(bottom= 0.1, hspace = 0.4)
+        self.fig.subplots_adjust(bottom= 0.1, right=0.8, hspace = 0.4)
         self.fig.suptitle("Measurement "+title, color="red")
+        
 
         # First plot: Phase and magnitude, Michael
         self.path_collection_phase = self.ax1[0].scatter([], [], c='red', marker='<', label='DUT Phase')
@@ -45,7 +49,15 @@ class MeasurementPlot:
         self.ax1[0].grid(True, linestyle=":")
         all_path_collections = [self.path_collection_phase, self.path_collection_mag, self.path_collection_equi0]
         labels = [pc.get_label() for pc in all_path_collections]
-        self.ax1[0].legend(all_path_collections, labels, loc='lower right')
+        self.ax1[0].legend(all_path_collections, labels, loc=self.legend_loc, bbox_to_anchor = \
+                           self.legend_bbox_to_anchor)
+            
+        ax = self.fig.axes
+        # plot delta values for phase and magnitude at left position outside the plot, Michael
+        self.annotation = ax[0].annotate('' ,xy=(0,1), \
+                                       xycoords='axes fraction', xytext=(-0.16,1), \
+                                       textcoords='axes fraction',fontsize = '16', \
+                                       horizontalalignment='left',verticalalignment='bottom')
 
         # Second plot: Humidity and temperature of climate chamber requested from internal sensors of chamber
         self.path_collection_temp = self.ax1[1].scatter([], [], c='blue', marker='p', label="Chamber Temperature")
@@ -66,7 +78,8 @@ class MeasurementPlot:
         self.ax1[1].grid(True, linestyle=":")
         all_path_collections = [self.path_collection_temp, self.path_collection_hum, self.path_collection_equi1]
         labels = [pc.get_label() for pc in all_path_collections]
-        self.ax1[1].legend(all_path_collections, labels, loc='lower right')
+        self.ax1[1].legend(all_path_collections, labels, loc=self.legend_loc, bbox_to_anchor = \
+                           self.legend_bbox_to_anchor)
         
         
         # Third plot:  parameter of external sensors
@@ -86,7 +99,8 @@ class MeasurementPlot:
         self.ax1[2].grid(True, linestyle=":")
         all_path_collections = [self.path_collection_temp_dut, self.path_collection_hum_dut]
         labels = [pc.get_label() for pc in all_path_collections]
-        self.ax1[2].legend(all_path_collections, labels, loc='lower right')
+        self.ax1[2].legend(all_path_collections, labels, loc=self.legend_loc, bbox_to_anchor = \
+                           self.legend_bbox_to_anchor)
         
         # Forth plot: parameter of external sensors
         # room temperature,  room humidity , air pressure room, Michael
@@ -98,7 +112,7 @@ class MeasurementPlot:
         self.path_collection_hum_room = self.sec_ext_hum_sens_axis.scatter([],[], c='orange', marker='>', label='room humidity')
         
         self.press_axis = self.ax1[3].twinx()
-        self.press_axis.spines['right'].set_position(('outward', 75))
+        self.press_axis.spines['right'].set_position(('outward', 60))
         self.path_collection_air_press_room = self.press_axis.scatter([],[], c='grey', marker='4', label='air pressure room')
         
         self.ax1[3].set_xlabel("TIMESTAMP")
@@ -110,7 +124,8 @@ class MeasurementPlot:
         all_path_collections = [self.path_collection_temp_room, self.path_collection_hum_room, \
                                 self.path_collection_air_press_room]
         labels = [pc.get_label() for pc in all_path_collections]
-        self.ax1[3].legend(all_path_collections, labels, loc='lower right')
+        self.ax1[3].legend(all_path_collections, labels, loc=self.legend_loc, bbox_to_anchor = \
+                           self.legend_bbox_to_anchor)
                 
         # Fifth plot: parameter of external sensors
         # meas instruments temperature,  meas instruments humidity, Michael
@@ -129,7 +144,8 @@ class MeasurementPlot:
         all_path_collections = [self.path_collection_temp_meas_instr, \
                                 self.path_collection_hum_meas_instr]
         labels = [pc.get_label() for pc in all_path_collections]
-        self.ax1[4].legend(all_path_collections, labels, loc='lower right')     
+        self.ax1[4].legend(all_path_collections, labels, loc=self.legend_loc, bbox_to_anchor = \
+                           self.legend_bbox_to_anchor)     
         
         
         
@@ -149,10 +165,12 @@ class MeasurementPlot:
         # all_path_collections = [self.path_collection_temp_heater, \
         #                         self.path_collection_hum_heater]
         # labels = [pc.get_label() for pc in all_path_collections]
-        # self.ax1[4].legend(all_path_collections, labels, loc='lower right')
+        # self.ax1[4].legend(all_path_collections, labels, loc=self.legend_loc, bbox_to_anchor = \ self.legend_bbox_to_anchor)
         
         #######################################################################################
-
+       
+        # sclae fontsize of all plot window elements to size 16, Michael
+        plt.rcParams.update({'font.size':16})
         
 
     def draw(self, data_frame, pdf_name=''):
-- 
GitLab