From 10449c076fd67fad3d3672a839cf07fdd7f93095 Mon Sep 17 00:00:00 2001
From: unknown <asoalexandros@gmail.com>
Date: Fri, 14 Feb 2025 16:48:34 +0100
Subject: [PATCH] backend destroys everything in  the plots

---
 hp4194/cv.py                 | 126 +++++++++++++++++------------------
 hp4194/cv_interace.ipynb     |  15 ++++-
 hp4194/examples/figure.ipynb |  10 ++-
 hp4194/help.py               |   6 +-
 hp4194/interface.py          |   1 -
 5 files changed, 79 insertions(+), 79 deletions(-)

diff --git a/hp4194/cv.py b/hp4194/cv.py
index 614a580..e07f4af 100644
--- a/hp4194/cv.py
+++ b/hp4194/cv.py
@@ -1,6 +1,5 @@
 from interface import *
 import control
-import matplotlib.pyplot as plt
 from help import *
 import time
 from IPython.display import clear_output
@@ -8,6 +7,7 @@ import numpy as np
 import datetime
 import pandas as pd
 
+import matplotlib.pyplot as plt
 
 #connect to device
 device = control.hp4194()
@@ -27,8 +27,6 @@ display(hbox1)
 hbox2=widgets.HBox([messparameter,sweep_parameter])
 display(hbox2,out)
 
-
-
 #add widgets to a list for disabling them
 all_widgets = [measure]
 add_widgets_to_list(sample_dict,all_widgets)
@@ -68,7 +66,7 @@ def on_measure_clicked(b):
         device.set_parameter('set_delay_apperture',sweep_parameter_dict['d_apperture'].value)
         device.set_parameter('aver_num',sweep_parameter_dict['averaging'].value)
         device.write((sweep_parameter_dict["integration"].value).lower()) # Set integration number
-    
+        
         # Now that we have set the frequency values ask user for calibration
         answer = ask_for_calibration()
         if answer == True : #perform an open calibration
@@ -115,10 +113,8 @@ def on_measure_clicked(b):
         # frequency index 
         f_index = messparameter_dict['f_point'].value-1
 
-        
-
         # create the figure
-        fig = plt.figure(layout = "constrained")
+        fig = plt.figure(figsize=(15,9),layout = "constrained")
         spec = fig.add_gridspec(ncols=3, nrows=2)
 
         ax1 = fig.add_subplot(spec[0,0])
@@ -161,8 +157,8 @@ def on_measure_clicked(b):
         ax6.set_ylabel("Cp (F)")
         ax6_twin.set_ylabel("D")
 
-        mng = plt.get_current_fig_manager()
-        mng.window.state('zoomed')
+        figManager = plt.get_current_fig_manager()
+        figManager.window.state('zoomed')
     
         for bias in biases:
             view["v-value"].value = str(bias) 
@@ -284,7 +280,7 @@ def on_measure_clicked(b):
                 ax6_twin.scatter(freq,D, color = 'y')
                 ax6_twin.tick_params(axis='y',labelcolor = 'y')
 
-            fig.draw()
+            plt.pause(0.1)
         if messparameter_dict["hysterisis"].value == True:
             reversed_biases = reversed_array(biases)
             for bias in reversed_biases:
@@ -351,64 +347,64 @@ def on_measure_clicked(b):
                 G_area_omega= G/area/omega
                 G_area_omega_values.extend(G_area_omega)
 
-                 # do the plots 
-            # first the live ones
-
-            #clear the live axes
-            ax1.clear()
-            ax1_twin.clear()
-            ax2.clear()
-            ax2_twin.clear()
-            ax3.clear()
-
-            # frequency Cp/D plot
-            ax1.plot(freq,Cp,color = 'b')
-            ax1.tick_params(axis = 'y',labelcolor = 'b')
-
-            ax1_twin.plot(freq,D, color = 'y')
-            ax1_twin.tick_params(axis='y',labelcolor = 'y')
-
-            # frequecy Z-phi
-            ax2.plot(freq,Z,color = 'b')
-            ax2.tick_params(axis = 'y',labelcolor = 'b')
-
-            ax2_twin.plot(freq,phi, color = 'y')
-            ax2_twin.tick_params(axis='y',labelcolor = 'y')
-
-            # Rez - Imz
-            ax3.plot(ReZ,ImZ,color = 'b')
-            ax3.tick_params(axis = 'y',labelcolor = 'b')
+                # do the plots 
+                # first the live ones
     
-            # now the rest of the plots
-            # Voltage vs Cp D for the user specified frequency 
-            # This is updated for every iteration
-            ax4.scatter(bias, Cp[f_index],color ='b')
-            ax4.tick_params(axis = 'y',labelcolor = 'b')
-
-            ax4_twin.scatter(bias, D[f_index],color ='y')
-            ax4_twin.tick_params(axis = 'y',labelcolor = 'y')
+                #clear the live axes
+                ax1.clear()
+                ax1_twin.clear()
+                ax2.clear()
+                ax2_twin.clear()
+                ax3.clear()
+    
+                # frequency Cp/D plot
+                ax1.plot(freq,Cp,color = 'b')
+                ax1.tick_params(axis = 'y',labelcolor = 'b')
+    
+                ax1_twin.plot(freq,D, color = 'y')
+                ax1_twin.tick_params(axis='y',labelcolor = 'y')
+    
+                # frequecy Z-phi
+                ax2.plot(freq,Z,color = 'b')
+                ax2.tick_params(axis = 'y',labelcolor = 'b')
+    
+                ax2_twin.plot(freq,phi, color = 'y')
+                ax2_twin.tick_params(axis='y',labelcolor = 'y')
+    
+                # Rez - Imz
+                ax3.plot(ReZ,ImZ,color = 'b')
+                ax3.tick_params(axis = 'y',labelcolor = 'b')
         
-            # Voltage, Z-phi
-            # This is also updated every iteration
-            ax5.scatter(bias, Z[f_index],color ='b')
-            ax4.tick_params(axis = 'y',labelcolor = 'b')
-
-            ax5_twin.scatter(bias, phi[f_index],color ='y')
-            ax5_twin.tick_params(axis = 'y',labelcolor = 'y')
-
-            # Final Plot 
-            # This if for all the frequencies for the calculated voltage
-
-            if biases[v_index]== bias:
-                ax6.scatter(freq,Cp,color = 'g')
-                ax6.tick_params(axis = 'y',labelcolor = 'g')
-
-                ax6_twin.scatter(freq,D, color = 'r')
-                ax6_twin.tick_params(axis='y',labelcolor = 'r')
-
-            fig.draw()
+                # now the rest of the plots
+                # Voltage vs Cp D for the user specified frequency 
+                # This is updated for every iteration
+                ax4.scatter(bias, Cp[f_index],color ='b')
+                ax4.tick_params(axis = 'y',labelcolor = 'b')
+    
+                ax4_twin.scatter(bias, D[f_index],color ='y')
+                ax4_twin.tick_params(axis = 'y',labelcolor = 'y')
+            
+                # Voltage, Z-phi
+                # This is also updated every iteration
+                ax5.scatter(bias, Z[f_index],color ='b')
+                ax4.tick_params(axis = 'y',labelcolor = 'b')
+    
+                ax5_twin.scatter(bias, phi[f_index],color ='y')
+                ax5_twin.tick_params(axis = 'y',labelcolor = 'y')
+    
+                # Final Plot 
+                # This if for all the frequencies for the calculated voltage
+    
+                if biases[v_index]== bias:
+                    ax6.scatter(freq,Cp,color = 'g')
+                    ax6.tick_params(axis = 'y',labelcolor = 'g')
+    
+                    ax6_twin.scatter(freq,D, color = 'r')
+                    ax6_twin.tick_params(axis='y',labelcolor = 'r')
+                
+                plt.pause(0.1)
 
-        fig.show()
+        plt.show()
         device.write('bias_off')
 
         # save to file
diff --git a/hp4194/cv_interace.ipynb b/hp4194/cv_interace.ipynb
index b362ce7..1100269 100644
--- a/hp4194/cv_interace.ipynb
+++ b/hp4194/cv_interace.ipynb
@@ -9,7 +9,7 @@
     {
      "data": {
       "application/vnd.jupyter.widget-view+json": {
-       "model_id": "7eecadb0c79443c5bcc6557fa72a4687",
+       "model_id": "0c5bba2a5cce41b1b8513e407f69feb7",
        "version_major": 2,
        "version_minor": 0
       },
@@ -23,7 +23,7 @@
     {
      "data": {
       "application/vnd.jupyter.widget-view+json": {
-       "model_id": "0c884157c9c84269ad3f115b708c9cc5",
+       "model_id": "195674067b164d529b9645afaafa3021",
        "version_major": 2,
        "version_minor": 0
       },
@@ -37,7 +37,7 @@
     {
      "data": {
       "application/vnd.jupyter.widget-view+json": {
-       "model_id": "5d847f78bee84f9ca987dee6e837be58",
+       "model_id": "a327e9646bee4cbdbfe82b7fbf83d0be",
        "version_major": 2,
        "version_minor": 0
       },
@@ -50,8 +50,17 @@
     }
    ],
    "source": [
+    "%matplotlib tk\n",
     "%run cv.py"
    ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "4f6be5c3-0ab8-4f18-88f6-02ce464a99f7",
+   "metadata": {},
+   "outputs": [],
+   "source": []
   }
  ],
  "metadata": {
diff --git a/hp4194/examples/figure.ipynb b/hp4194/examples/figure.ipynb
index 510fb9f..8525327 100644
--- a/hp4194/examples/figure.ipynb
+++ b/hp4194/examples/figure.ipynb
@@ -2,17 +2,17 @@
  "cells": [
   {
    "cell_type": "code",
-   "execution_count": 15,
+   "execution_count": 1,
    "id": "52e7274d-b638-4da1-acca-94cfc0c86c5a",
    "metadata": {},
    "outputs": [],
    "source": [
-    "%matplotlib tk"
+    "%matplotlib qt"
    ]
   },
   {
    "cell_type": "code",
-   "execution_count": 19,
+   "execution_count": 2,
    "id": "0a1db92b-e4d3-49f4-a95f-40d58e575404",
    "metadata": {},
    "outputs": [],
@@ -63,8 +63,6 @@
     "ax6.set_ylabel(\"Cp (F)\")\n",
     "ax6_twin.set_ylabel(\"D\")\n",
     "\n",
-    "mng = plt.get_current_fig_manager()\n",
-    "mng.window.state('zoomed')\n",
     "\n",
     "fig.show()"
    ]
@@ -94,7 +92,7 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
-   "version": "3.12.0"
+   "version": "3.13.0"
   }
  },
  "nbformat": 4,
diff --git a/hp4194/help.py b/hp4194/help.py
index e4c513f..f90210d 100644
--- a/hp4194/help.py
+++ b/hp4194/help.py
@@ -18,10 +18,8 @@ def change_state(widgets_list):
 def ask_for_calibration():
     root = tk.Tk()
     root.withdraw()
-    root.lift() #show window above all other applications
-
-    root.attributes("-topmost", True)#window stays above all other applications
-
+    root.attributes("-topmost",True)
+    root.update()
     answer=tk.messagebox.askyesno(message='Do you want to calibarate?')
 
     root.destroy()
diff --git a/hp4194/interface.py b/hp4194/interface.py
index 4f2fb49..901c473 100644
--- a/hp4194/interface.py
+++ b/hp4194/interface.py
@@ -138,7 +138,6 @@ def control_panel():
     control_panel[3,0] = widgets.Label("Actual Voltage",layout=Layout(height='auto', width = width))
 
     control_panel[4,0] = widgets.Text(disabled = True,layout=Layout(height='auto', width = width))
-    control_panel[4,1] = widgets.Checkbox(description = 'Clear Graphs',value = True,indent = False,layout=Layout(height='auto', width = width))
 
     measure = control_panel[0,:]
 
-- 
GitLab