diff --git a/Python_script/analysis.py b/Python_script/analysis.py
index d1e93a80eabf0e8270beb0471ae9ede367b65893..91835aff760f935480ecc541dfa704fce7611859 100644
--- a/Python_script/analysis.py
+++ b/Python_script/analysis.py
@@ -2,7 +2,6 @@ import pandas as pd
 import matplotlib.pyplot as plt
 import math
 
-
 def extract_stable_data(datafile):
     datapoint = {}
     #df is a pandas data frame
@@ -30,20 +29,27 @@ def extract_stable_data(datafile):
     return datapoint
 
 
-def plot_temperature_sweep(temperatures, humidity, basename):
-    temps_from_data = []
+# sweep_type is either 'temperature' or 'humidity'
+def plot_sweep(temperatures, humidities, basename, sweep_type):
+    x_data = []
     phases = []
     phase_vars = []
     magnitudes = []
     magnitude_vars = []
-    for temp in temperatures:
-        datafile = basename+'_'+str(temp)+'deg_'+str(humidity)+'rh.csv'
+    for temp, hum in zip(temperatures, humidities):
+        datafile = basename+'_'+str(temp)+'deg_'+str(hum)+'rh.csv'
         print(datafile)
         datapoint = extract_stable_data(datafile)
         if datapoint is None:
             continue
-        
-        temps_from_data.append(datapoint['temperature_mean'])
+
+        if sweep_type == 'temperature':
+            x_data.append(datapoint['temperature_mean'])
+        elif sweep_type == 'humidity':
+            x_data.append(datapoint['humidity_mean'])
+        else:
+            raise Exception('Unknown sweep_type:'+str(sweep_type))
+
         phases.append(datapoint['phase_mean'])
         phase_vars.append(datapoint['phase_var'])
         magnitudes.append(datapoint['magnitude_mean'])
@@ -55,14 +61,20 @@ def plot_temperature_sweep(temperatures, humidity, basename):
 
     fig, ax1 = plt.subplots()
 
-    plt.title(basename + ': Temperature sweep at ' + str(humidity) + ' % r.h.')
+    if sweep_type == 'temperature':
+        plt.title(basename + ': Temperature sweep at ' + str(humidities[0]) + ' % r.h.')
+        ax1.set_xlabel('temperature [deg C]')
+    elif sweep_type == 'humidity':
+        plt.title(basename + ': Humidity sweep at ' + str(temperatures[0]) + ' deg C')
+        ax1.set_xlabel('relative humidity [%]')
+    else:
+        raise Exception('Unknown sweep_type:'+str(sweep_type))
 
-    ax1.errorbar(temps_from_data, phases, phase_vars, marker='+', linewidth=0)
-    ax1.set_xlabel('temperature [deg C]')
+    ax1.errorbar(x_data, phases, phase_vars, marker='+', linewidth=0)
     ax1.set_ylabel('S21 phase [deg]', color='blue')
 
     ax2 = ax1.twinx()
-    ax2.errorbar(temps_from_data, magnitudes_db, magnitude_vars_db, marker='x', color='red', linewidth=0)
+    ax2.errorbar(x_data, magnitudes_db, magnitude_vars_db, marker='x', color='red', linewidth=0)
     ax2.set_ylabel('S21 magnitude [dB]', color='red')
     
     fig.tight_layout()  # otherwise the right y-label is slightly clipped
@@ -70,6 +82,4 @@ def plot_temperature_sweep(temperatures, humidity, basename):
 
 
 if __name__ == '__main__':
-    plot_temperature_sweep(range(20, 30+1), 40, 'tempsweep1')
-
-     
+   plot_sweep(range(20, 30+1), [40]*11, 'tempsweep1', 'temperature')
diff --git a/Python_script/prototype.py b/Python_script/prototype.py
index 6ead4c92e688496fbbba6fc87b0f79061bb1874c..a29781ff88429fc21a9d1247779d200bbd48a7a0 100755
--- a/Python_script/prototype.py
+++ b/Python_script/prototype.py
@@ -411,7 +411,7 @@ if __name__ == '__main__':
             temp_extensions = []
             for t in temperatures:
                 temp_extensions.append(str(t)+'deg_'+str(humidity)+'rh')
-            analysis.plot_temperature_sweep(temperatures, humidity, output_basename)
+            analysis.plot_sweep(temperatures, [humidity]*len(temperatures), output_basename, 'temperature')
             plot_output(output_basename, temp_extensions, args.plot, output_basename + ': Temperature sweep ' +
                         str(temperatures[0]) + ' degC to ' + str(temperatures[-1]) + ' degC')
             print(str(temp_extensions))