@@ -21,23 +21,23 @@ def plot_circuit(component):
2121 return iklayout .show (path )
2222
2323
24- def plot_losses (losses : list [float ], iterations : list [int ] = None ):
24+ def plot_losses (losses : list [float ], iterations : list [int ] = [] ):
2525 """
2626 Plot a list of losses with labels.
2727
2828 Args:
2929 losses: List of loss values.
3030 """
31-
31+ iterations = list ( range ( len ( losses ))) if iterations == [] else iterations
3232 plt .figure (figsize = (10 , 5 ))
3333 plt .title ("Losses vs. Iterations" )
3434 plt .xlabel ("Iterations" )
3535 plt .ylabel ("Losses" )
36- plt .plot (losses )
36+ plt .plot (iterations , losses )
3737 plt .show ()
3838
3939
40- def plot_constraints (constraints : list [list [float ]], constraints_labels : list [str ], iterations : list [str ] = None ):
40+ def plot_constraints (constraints : list [list [float ]], constraints_labels : list [str ], iterations : list [int ] = [] ):
4141 """
4242 Plot a list of constraints with labels.
4343
@@ -47,23 +47,23 @@ def plot_constraints(constraints: list[list[float]], constraints_labels: list[st
4747 """
4848
4949 constraints_labels = constraints_labels or [f"Constraint { i } " for i in range (len (constraints [0 ]))]
50- iterations = iterations or range (len (constraints [0 ]))
50+ iterations = iterations or list ( range (len (constraints [0 ]) ))
5151
5252 plt .figure (figsize = (10 , 5 ))
5353 plt .title ("Losses vs. Iterations" )
5454 plt .xlabel ("Iterations" )
5555 plt .ylabel ("Constraints" )
5656 for i , constraint in enumerate (constraints ):
57- plt .plot (constraint , label = constraints_labels [i ])
57+ plt .plot (iterations , constraint , label = constraints_labels [i ])
5858 plt .legend ()
5959 plt .grid (True )
6060 plt .show ()
6161
6262
6363def plot_single_spectrum (spectrum : list [float ],
6464 wavelengths : list [float ],
65- vlines : list [float ] = None ,
66- hlines : list [float ] = None ):
65+ vlines : list [float ] = [] ,
66+ hlines : list [float ] = [] ):
6767 """
6868 Plot a single spectrum with vertical and horizontal lines.
6969 """
@@ -84,12 +84,12 @@ def plot_single_spectrum(spectrum: list[float],
8484
8585
8686def plot_interactive_spectrums (
87- spectrums : list [list [list [float ]]] | list [ list [ float ]] ,
87+ spectrums : list [list [list [float ]]],
8888 wavelengths : list [float ],
89- spectrum_labels : list [str ] = None ,
90- slider_index : list [int ] = None ,
91- vlines : list [float ] = None ,
92- hlines : list [float ] = None ,
89+ spectrum_labels : list [str ] = [] ,
90+ slider_index : list [int ] = [] ,
91+ vlines : list [float ] = [] ,
92+ hlines : list [float ] = [] ,
9393):
9494 """
9595 Creates an interactive plot of spectrums with a slider to select different indices.
@@ -124,10 +124,8 @@ def plot_interactive_spectrums(
124124 y_min = min (min (min (arr2 ) for arr2 in arr1 ) for arr1 in spectrums )
125125 y_max = max (max (max (arr2 ) for arr2 in arr1 ) for arr1 in spectrums )
126126
127- slider_index = slider_index or range (len (spectrums [0 ]))
128- vlines = vlines or []
129- hlines = hlines or []
130- spectrum_labels = spectrum_labels or [f"Spectrum{ i } " for i in range (len (spectrums ))]
127+ slider_index = slider_index if slider_index != [] else list (range (len (spectrums [0 ])))
128+ spectrum_labels = spectrum_labels if spectrum_labels != [] else [f"Spectrum{ i } " for i in range (len (spectrums ))]
131129
132130 # Function to update the plot
133131 def plot_array (index = 0 ):
0 commit comments