@@ -47,7 +47,9 @@ def save_data_to_csv(csv_vals, csv_file):
4747 return
4848
4949
50- def plot_to_file (title , data , dir_name , filename , xlabel = None , x_lim = None , ylabel = None , y_lim = None , data1 = None , x_data = None , data_marked = None ):
50+ def plot_to_file (title , data , dir_name , filename , xlabel = None , x_lim = None ,
51+ ylabel = None , y_lim = None , data1 = None , x_data = None ,
52+ data_marked = None , label0 = "CH0" , label1 = "CH1" ):
5153 # Saves the plots in a separate folder
5254 # Arguments:
5355 # title -- Title of the plot
@@ -58,10 +60,12 @@ def plot_to_file(title, data, dir_name, filename, xlabel=None, x_lim = None, yla
5860 # ylabel -- Label of y-Axis(default: {None})
5961 # data1 -- Data that should be plotted on the same plot(default: {None})
6062 # data_marked -- Data that represents specific points on the plot(default: {None})
63+ # label0 -- Legend label for first dataset (default: {"CH0"})
64+ # label1 -- Legend label for second dataset (default: {"CH1"})
6165 # plot the signals in a separate folder
6266 plt .title (title )
6367 # if xlabel and ylabel are not specified there will be default values
64- if xlabel is not None :
68+ if xlabel is not None :
6569 plt .xlabel (xlabel )
6670 else :
6771 plt .xlabel ('Samples' )
@@ -72,22 +76,23 @@ def plot_to_file(title, data, dir_name, filename, xlabel=None, x_lim = None, yla
7276 plt .grid (visible = True )
7377 # if x_data is not None, the plot will be displayed with the specified x_data
7478 if x_data is not None :
75- plt .plot (x_data , data )
79+ plt .plot (x_data , data , label = label0 )
7680 else :
77- plt .plot (data )
81+ plt .plot (data , label = label0 )
7882 # if a second set of data must be printed (for ch0 and ch1 phase difference in this case)
7983 if data1 is not None :
8084 if x_data is not None :
81- plt .plot (x_data , data1 )
85+ plt .plot (x_data , data1 , label = label1 )
8286 else :
83- plt .plot (data1 )
87+ plt .plot (data1 , label = label1 )
8488 # Optional configurations
8589 if x_lim is not None :
8690 plt .xlim (* x_lim )
8791 if y_lim is not None :
8892 plt .ylim (* y_lim )
8993 if data_marked is not None :
90- plt .plot (data_marked , data [data_marked ], 'xr' )
94+ plt .plot (data_marked , data [data_marked ], 'xr' )
95+ plt .legend ()
9196 plt .savefig (dir_name + "/" + filename )
9297 plt .close ()
9398 return
0 commit comments