def plot_signals(signal_list, sync=True, navigator="auto", navigator_list=None, **kwargs): """Plot several signals at the same time. Parameters ---------- signal_list : list of BaseSignal instances If sync is set to True, the signals must have the same navigation shape, but not necessarily the same signal shape. sync : True or False, default "True" If True: the signals will share navigation, all the signals must have the same navigation shape for this to work, but not necessarily the same signal shape. navigator : {"auto", None, "spectrum", "slider", BaseSignal}, default "auto" See signal.plot docstring for full description navigator_list : {List of navigator arguments, None}, default None Set different navigator options for the signals. Must use valid navigator arguments: "auto", None, "spectrum", "slider", or a hyperspy Signal. The list must have the same size as signal_list. If None, the argument specified in navigator will be used. **kwargs Any extra keyword arguments are passed to each signal `plot` method. Example ------- >>> s_cl = hs.load("coreloss.dm3") >>> s_ll = hs.load("lowloss.dm3") >>> hs.plot.plot_signals([s_cl, s_ll]) Specifying the navigator: >>> s_cl = hs.load("coreloss.dm3") >>> s_ll = hs.load("lowloss.dm3") >>> hs.plot.plot_signals([s_cl, s_ll], navigator="slider") Specifying the navigator for each signal: >>> s_cl = hs.load("coreloss.dm3") >>> s_ll = hs.load("lowloss.dm3") >>> s_edx = hs.load("edx.dm3") >>> s_adf = hs.load("adf.dm3") >>> hs.plot.plot_signals( [s_cl, s_ll, s_edx], navigator_list=["slider",None,s_adf]) """ import hyperspy.signal if navigator_list: if not (len(signal_list) == len(navigator_list)): raise ValueError("signal_list and navigator_list must" " have the same size") if sync: axes_manager_list = [] for signal in signal_list: axes_manager_list.append(signal.axes_manager) if not navigator_list: navigator_list = [] if navigator is None: navigator_list.extend([None] * len(signal_list)) elif navigator is "slider": navigator_list.append("slider") navigator_list.extend([None] * (len(signal_list) - 1)) elif isinstance(navigator, hyperspy.signal.BaseSignal): navigator_list.append(navigator) navigator_list.extend([None] * (len(signal_list) - 1)) elif navigator is "spectrum": navigator_list.extend(["spectrum"] * len(signal_list)) elif navigator is "auto": navigator_list.extend(["auto"] * len(signal_list)) else: raise ValueError("navigator must be one of \"spectrum\",\"auto\"," " \"slider\", None, a Signal instance") # Check to see if the spectra have the same navigational shapes temp_shape_first = axes_manager_list[0].navigation_shape for i, axes_manager in enumerate(axes_manager_list): temp_shape = axes_manager.navigation_shape if not (temp_shape_first == temp_shape): raise ValueError( "The spectra does not have the same navigation shape") axes_manager_list[i] = axes_manager.deepcopy() if i > 0: for axis0, axisn in zip(axes_manager_list[0].navigation_axes, axes_manager_list[i].navigation_axes): axes_manager_list[i]._axes[axisn.index_in_array] = axis0 del axes_manager for signal, navigator, axes_manager in zip(signal_list, navigator_list, axes_manager_list): signal.plot(axes_manager=axes_manager, navigator=navigator, **kwargs) # If sync is False else: if not navigator_list: navigator_list = [] navigator_list.extend([navigator] * len(signal_list)) for signal, navigator in zip(signal_list, navigator_list): signal.plot(navigator=navigator, **kwargs)
def plot_signals(signal_list, sync=True, navigator="auto", navigator_list=None, **kwargs): """Plot several signals at the same time. Parameters ---------- signal_list : list of Signal instances If sync is set to True, the signals must have the same navigation shape, but not necessarily the same signal shape. sync : True or False, default "True" If True: the signals will share navigation, all the signals must have the same navigation shape for this to work, but not necessarily the same signal shape. navigator : {"auto", None, "spectrum", "slider", Signal}, default "auto" See signal.plot docstring for full description navigator_list : {List of navigator arguments, None}, default None Set different navigator options for the signals. Must use valid navigator arguments: "auto", None, "spectrum", "slider", or a hyperspy Signal. The list must have the same size as signal_list. If None, the argument specified in navigator will be used. **kwargs Any extra keyword arguments are passed to each signal `plot` method. Example ------- >>> s_cl = hs.load("coreloss.dm3") >>> s_ll = hs.load("lowloss.dm3") >>> hs.plot.plot_signals([s_cl, s_ll]) Specifying the navigator: >>> s_cl = hs.load("coreloss.dm3") >>> s_ll = hs.load("lowloss.dm3") >>> hs.plot.plot_signals([s_cl, s_ll], navigator="slider") Specifying the navigator for each signal: >>> s_cl = hs.load("coreloss.dm3") >>> s_ll = hs.load("lowloss.dm3") >>> s_edx = hs.load("edx.dm3") >>> s_adf = hs.load("adf.dm3") >>> hs.plot.plot_signals( [s_cl, s_ll, s_edx], navigator_list=["slider",None,s_adf]) """ import hyperspy.signal if navigator_list: if not (len(signal_list) == len(navigator_list)): raise ValueError( "signal_list and navigator_list must" " have the same size") if sync: axes_manager_list = [] for signal in signal_list: axes_manager_list.append(signal.axes_manager) if not navigator_list: navigator_list = [] if navigator is None: navigator_list.extend([None] * len(signal_list)) elif navigator is "slider": navigator_list.append("slider") navigator_list.extend([None] * (len(signal_list) - 1)) elif isinstance(navigator, hyperspy.signal.Signal): navigator_list.append(navigator) navigator_list.extend([None] * (len(signal_list) - 1)) elif navigator is "spectrum": navigator_list.extend(["spectrum"] * len(signal_list)) elif navigator is "auto": navigator_list.extend(["auto"] * len(signal_list)) else: raise ValueError( "navigator must be one of \"spectrum\",\"auto\"," " \"slider\", None, a Signal instance") # Check to see if the spectra have the same navigational shapes temp_shape_first = axes_manager_list[0].navigation_shape for i, axes_manager in enumerate(axes_manager_list): temp_shape = axes_manager.navigation_shape if not (temp_shape_first == temp_shape): raise ValueError( "The spectra does not have the same navigation shape") axes_manager_list[i] = axes_manager.deepcopy() if i > 0: for axis0, axisn in zip(axes_manager_list[0].navigation_axes, axes_manager_list[i].navigation_axes): axes_manager_list[i]._axes[axisn.index_in_array] = axis0 del axes_manager for signal, navigator, axes_manager in zip(signal_list, navigator_list, axes_manager_list): signal.plot(axes_manager=axes_manager, navigator=navigator, **kwargs) # If sync is False else: if not navigator_list: navigator_list = [] navigator_list.extend([navigator] * len(signal_list)) for signal, navigator in zip(signal_list, navigator_list): signal.plot(navigator=navigator, **kwargs)