def motion(self,event):
        x_move = event.xdata
        y_move = event.ydata
        if opt !=2:

            if self.a0 == event.inaxes:
                # print("Moving through X-Y plot")
                # x, y = event.inaxes.transData.inverted().transform((event.x, event.y)) #transforma de coordenadas del Tkinker Canvas a coordenadas del matplotlib plot
                # print("Mouse position: (%s %s)" % (x, y))
                x_lst = find_nearest(xy_pos_df.iloc[:,0],x_move)
                y_lst = find_nearest(xy_pos_df.iloc[:,1], y_move)
                # print(x_lst,y_lst)
                mouse_pos = xy_pos_df[(xy_pos_df.iloc[:, 0] == x_lst) & (xy_pos_df.iloc[:, 1] == y_lst)].index.tolist()
                # print(mouse_pos)
                self.a1.clear()
                self.a1.set_ylabel('Intensity [a.u.]')
                self.a1.set_xlabel('Wavelength [nm]')
                if len(mouse_pos) == 0:
                    pass
                else:
                    if opt == 0:
                        self.a1.plot(wavel_df.iloc[:, 0], inten_df.iloc[mouse_pos, :].transpose(), '*')
                    if opt == 1:
                        # spectrum = np.column_stack((wavel_array,np.transpose(inten_array[mouse_pos,:])))
                        # np.asarray(wavel_array, inten_file.iloc[mouse_pos,:].transpose())
                        # w,I = spectrum_subplot(spectrum)
                        clim = (350, 780)
                        norm = plt.Normalize(*clim)
                        wl = np.arange(clim[0], clim[1] + 1, 2)
                        colorlist = list(zip(norm(wl), [wavelength_to_rgb(w) for w in wl]))
                        spectralmap = matplotlib.colors.LinearSegmentedColormap.from_list("spectrum", colorlist)
                        mouse_pos = mouse_pos[0]
                        wavelengths = wavel_array #wavel_array[:, 0]
                        spectrum = np.transpose(inten_array[mouse_pos, :])
                        plt.plot(wavel_array, spectrum, color='darkred')

                        y = np.linspace(0, np.max(spectrum), 100)
                        X, Y = np.meshgrid(wavelengths, y)

                        extent = (np.min(wavelengths), np.max(wavelengths), np.min(y), np.max(y))

                        plt.imshow(X, clim=clim, extent=extent, cmap=spectralmap, aspect='auto')
                        plt.xlabel('Wavelength [nm]')
                        plt.ylabel('Intensity [a.u.]')

                        plt.fill_between(wavelengths, spectrum, np.max(spectrum), color='w')
                    # if opt == 3:
                    #     clim = (350, 780)
                    #     norm = plt.Normalize(*clim)
                    #     wl = np.arange(clim[0], clim[1] + 1, 2)
                    #     colorlist = list(zip(norm(wl), [wavelength_to_rgb(w) for w in wl]))
                    #     spectralmap = matplotlib.colors.LinearSegmentedColormap.from_list("spectrum", colorlist)
                    #     mouse_pos = mouse_pos[0]
                    #     wavelengths = wavel_array  # wavel_array[:, 0]
                    #     spectrum = np.transpose(inten_array[mouse_pos, :])
                    #     plt.plot(wavel_array, spectrum, color='darkred')
                    #
                    #     y = np.linspace(0, np.max(spectrum), 100)
                    #     X, Y = np.meshgrid(wavelengths, y)
                    #
                    #     extent = (np.min(wavelengths), np.max(wavelengths), np.min(y), np.max(y))
                    #
                    #     plt.imshow(X, clim=clim, extent=extent, cmap=spectralmap, aspect='auto')
                    #     plt.xlabel('Wavelength [nm]')
                    #     plt.ylabel('Intensity [a.u.]')
                    #
                    #     plt.fill_between(wavelengths, spectrum, np.max(spectrum), color='w')

            else:
                self.a1.clear()
                self.a1.set_ylabel('Intensity [a.u.]')
                self.a1.set_xlabel('Wavelength [nm]')
                return
    def motion(self, event):
        x_move = event.xdata
        y_move = event.ydata
        if opt == 0 or opt == 1:

            if self.a0 == event.inaxes:
                x_lst = find_nearest(xy_pos_df.iloc[:, 0], x_move)
                y_lst = find_nearest(xy_pos_df.iloc[:, 1], y_move)
                mouse_pos = xy_pos_df[(xy_pos_df.iloc[:, 0] == x_lst) & (
                    xy_pos_df.iloc[:, 1] == y_lst)].index.tolist()
                self.a1.clear()
                self.a1.set_ylabel('Intensity [a.u.]')
                self.a1.set_xlabel('Wavelength [nm]')
                if len(mouse_pos) == 0:
                    pass
                else:
                    if normalization:
                        tmp = 1 / light_df.iloc[:]
                        tmp[light_df.iloc[:] < 0.1] = 0
                        inten_norm = (inten_df.iloc[mouse_pos, :] * tmp).abs()
                        # print(inten_norm)
                        if opt == 0:
                            self.a1.plot(wavel_df.iloc[:, 0],
                                         inten_norm.transpose(), '*')
                        elif opt == 1:
                            clim = (350, 780)
                            norm = plt.Normalize(*clim)
                            wl = np.arange(clim[0], clim[1] + 1, 2)
                            colorlist = list(
                                zip(norm(wl),
                                    [wavelength_to_rgb(w) for w in wl]))
                            spectralmap = matplotlib.colors.LinearSegmentedColormap.from_list(
                                "spectrum", colorlist)
                            mouse_pos = mouse_pos[0]
                            wavelengths = wavel_array
                            spectrum = np.transpose(inten_norm)
                            # print(spectrum)
                            self.a1.plot(wavel_array,
                                         spectrum,
                                         color='darkred')
                            # print(np.max(spectrum))
                            y = np.linspace(0, np.max(spectrum), 100)
                            X, Y = np.meshgrid(wavelengths, y)

                            extent = (np.min(wavelengths), np.max(wavelengths),
                                      np.min(y), np.max(y))

                            plt.imshow(X,
                                       clim=clim,
                                       extent=extent,
                                       cmap=spectralmap,
                                       aspect='auto')
                            plt.xlabel('Wavelength [nm]')
                            plt.ylabel('Intensity [a.u.]')

                            plt.fill_between(wavelengths,
                                             spectrum,
                                             np.max(spectrum),
                                             color='w')

                    if not normalization:
                        if opt == 0:
                            self.a1.plot(
                                wavel_df.iloc[:, 0],
                                inten_df.iloc[mouse_pos, :].transpose(), '*')
                        elif opt == 1:
                            clim = (350, 780)
                            norm = plt.Normalize(*clim)
                            wl = np.arange(clim[0], clim[1] + 1, 2)
                            colorlist = list(
                                zip(norm(wl),
                                    [wavelength_to_rgb(w) for w in wl]))
                            spectralmap = matplotlib.colors.LinearSegmentedColormap.from_list(
                                "spectrum", colorlist)
                            mouse_pos = mouse_pos[0]
                            wavelengths = wavel_array
                            spectrum = np.transpose(
                                inten_df.iloc[mouse_pos, :])
                            self.a1.plot(wavel_array,
                                         spectrum,
                                         color='darkred')
                            y = np.linspace(0, np.max(spectrum), 100)
                            X, Y = np.meshgrid(wavelengths, y)

                            extent = (np.min(wavelengths), np.max(wavelengths),
                                      np.min(y), np.max(y))

                            plt.imshow(X,
                                       clim=clim,
                                       extent=extent,
                                       cmap=spectralmap,
                                       aspect='auto')
                            plt.xlabel('Wavelength [nm]')
                            plt.ylabel('Intensity [a.u.]')

                            plt.fill_between(wavelengths,
                                             spectrum,
                                             np.max(spectrum),
                                             color='w')

            else:
                self.a1.clear()
                self.a1.set_ylabel('Intensity [a.u.]')
                self.a1.set_xlabel('Wavelength [nm]')
                return
示例#3
0
# inten_dff = banda_panc_df.iloc[0].values - abs(back_df.iloc[689].values*0.1)
inten_dff = inten_df.iloc[200].values  # - abs(inten_df.iloc[500].values)
lighta = light_dff[940:3500]
intena = inten_dff[940:3500]
# intend = intena/abs(lighta)
inten = intena.transpose()

from scipy.signal import savgol_filter

yhat = savgol_filter(inten, 55, 3)

plt.grid()
clim = (350, 780)
norm = plt.Normalize(*clim)
wl = np.arange(clim[0], clim[1] + 1, 2)
colorlist = list(zip(norm(wl), [wavelength_to_rgb(w) for w in wl]))
spectralmap = matplotlib.colors.LinearSegmentedColormap.from_list(
    "spectrum", colorlist)
wavel_array = wavel_dff.iloc[:, 0].values
spectrum = yhat
plt.plot(wavel_dff, spectrum, color='darkred')
y = np.linspace(0, np.max(spectrum), 100)
X, Y = np.meshgrid(wavel_array, y)

extent = (np.min(wavel_array), np.max(wavel_array), np.min(y), np.max(y))

plt.imshow(X, clim=clim, extent=extent, cmap=spectralmap, aspect='auto')
plt.xlabel('Longitud de onda [nm]', fontsize=20)
plt.ylabel('Transmisión [u.a.]', fontsize=20)
plt.ylim([0, 1])
plt.fill_between(wavel_array, spectrum, np.max(spectrum), color='w')