@@ -98,7 +98,7 @@ def plot_single_spectrum(
9898
9999
100100def plot_interactive_spectra (
101- spectra : Union [List [List [List [float ]]], Dict [Tuple [str , str ], List [List [float ]]]],
101+ spectra : Union [List [List [List [float ]]], Dict [Union [ Tuple [str , str ] , str ], List [List [float ]]]],
102102 wavelengths : List [float ],
103103 spectrum_labels : Optional [List [str ]] = None ,
104104 vlines : Optional [List [float ]] = None ,
@@ -118,15 +118,17 @@ def plot_interactive_spectra(
118118 hlines : list of float, optional
119119 A list of y-values where horizontal lines should be drawn. Defaults to an empty list.
120120 """
121+ if isinstance (spectra , dict ):
122+ port_keys = []
123+ for key in spectra :
124+ if isinstance (key , str ):
125+ port_keys .append ((key .split ("," )[0 ], key .split ("," )[1 ]))
126+ elif isinstance (key , tuple ):
127+ port_keys .append (key )
121128
122129 # Defaults
123130 if spectrum_labels is None and isinstance (spectra , dict ):
124- if all (isinstance (key , str ) and "," in key for key in spectra .keys ()):
125- spectrum_labels = [f"T { ports .split (',' )[0 ]} -> { ports .split (',' )[1 ]} " for ports in spectra .keys ()]
126- elif all (isinstance (key , tuple ) and len (key ) == 2 for key in spectra .keys ()):
127- spectrum_labels = [f"T { port_in } -> { port_out } " for port_in , port_out in spectra .keys ()]
128- else :
129- raise ValueError ("Invalid keys for spectra dictionary." )
131+ spectrum_labels = [f"T { port_in } -> { port_out } " for port_in , port_out in port_keys ]
130132
131133 elif spectrum_labels is None :
132134 spectrum_labels = [f"Spectrum { i } " for i in range (len (spectra ))]
0 commit comments