Ejemplo n.º 1
0
    def lattice(self,
                ms=20,
                lw=5.,
                c=3.,
                fs=20,
                axis=False,
                plt_hop=False,
                plt_hop_low=False,
                plt_index=False,
                figsize=None):
        '''
        Plot lattice.

        :param ms: Positive number. Default value 20. Markersize.
        :param c: Positive number. Default value 3. 
            Coefficient. Hopping linewidths given by c*hop['t'].
        :param fs: Positive number. Default value 20. Fontsize.
        :param plt_hop: Boolean. Default value False. Plot hoppings.
        :param plt_hop_low: Boolean. Default value False. 
            Plot hoppings diagonal low.
        :param plt_index: Boolean. Default value False. Plot site labels.
        :param axis: Boolean. Default value False. Plot axis.
        :param figsize: Tuple. Default value None. Figure size.

        :returns:
            * **fig** -- Figure.
        '''
        error_handling.empty_ndarray(self.sys.lat.coor, 'lat.get_lattice')
        return self.lattice_generic(self.sys.lat.coor, ms, lw, c, fs, axis,
                                    plt_hop, plt_hop_low, plt_index, figsize)
Ejemplo n.º 2
0
Archivo: plot.py Proyecto: cpoli/tbee
    def intensity_1d(self, intensity, ms=20., lw=2., fs=20., title=r'$|\psi^{(j)}|^2$'):
        '''
        Plot intensity for 1D lattices.

        :param intensity: np.array. Field intensity.
        :param ms: Positive Float. Default value 20. Markersize.
        :param lw: Positive Float. Default value 2. Linewith, connect sublattice sites.
        :param fs: Positive Float. Default value 20. Font size.
        :param title: String. Default value 'Intensity'. Figure title.
        '''
        error_handling.ndarray(intensity, 'intensity', self.sys.lat.sites)
        error_handling.empty_ndarray(self.sys.lat.coor, 'sys.get_lattice')
        error_handling.positive_real(ms, 'ms')
        error_handling.positive_real(lw, 'lw')
        error_handling.positive_real(fs, 'fs')
        error_handling.string(title, 'title')
        fig, ax = plt.subplots()
        ax.set_xlabel('$j$', fontsize=fs)
        ax.set_ylabel(title, fontsize=fs)
        ax.set_title(title, fontsize=fs)
        for t, c in zip(self.sys.lat.tags, self.colors):
            plt.plot(self.sys.lat.coor['x'][self.sys.lat.coor['tag'] == t],
                        intensity[self.sys.lat.coor['tag'] == t],
                        '-o', color=c, ms=ms, lw=lw)
        plt.xlim([-1., self.sys.lat.sites])
        plt.ylim([0., np.max(intensity)+.05])
        fig.set_tight_layout(True)
        plt.draw()
        return fig
Ejemplo n.º 3
0
Archivo: plot.py Proyecto: cpoli/tbee
 def spectrum_hist(self, nbr_bins=61, fs=20, lims=None):
     """
     Plot the spectrum.
         
     :param nbr_bins: Default value 101. Number of bins of the histogram.
     :param lims: List, lims[0] energy min, lims[1] energy max.
     """
     error_handling.empty_ndarray(self.sys.en, 'sys.get_eig')
     error_handling.positive_real(nbr_bins, 'nbr_bins')
     error_handling.lims(lims)
     fig, ax = plt.subplots()
     if lims is None:
         en_max = np.max(self.sys.en.real)
         ind_en = np.ones(self.sys.lat.sites, bool)
         ax.set_ylim([-en_max, en_max])
     else:
         ind_en = np.argwhere((self.sys.en > lims[0]) & (self.sys.en < lims[1]))
         ind_en = np.ravel(ind_en)
         ax.set_xlim(lims)
     en = self.sys.en[ind_en]
     n, bins, patches = plt.hist(en, bins=nbr_bins, color='b', alpha=0.8)
     ax.set_title('Spectrum', fontsize=fs)
     ax.set_xlabel('$E$', fontsize=fs)
     ax.set_ylabel('number of states', fontsize=fs)
     ax.set_ylim([0, np.max(n)+1])
     for label in ax.xaxis.get_majorticklabels():
         label.set_fontsize(fs)
     for label in ax.yaxis.get_majorticklabels():
         label.set_fontsize(fs)
Ejemplo n.º 4
0
 def spectrum_hist(self, nbr_bins=61, fs=20, lims=None):
     """
     Plot the spectrum.
         
     :param nbr_bins: Default value 101. Number of bins of the histogram.
     :param lims: List, lims[0] energy min, lims[1] energy max.
     """
     error_handling.empty_ndarray(self.sys.en, 'sys.get_eig')
     error_handling.positive_real(nbr_bins, 'nbr_bins')
     error_handling.lims(lims)
     fig, ax = plt.subplots()
     if lims is None:
         en_max = np.max(self.sys.en.real)
         ind_en = np.ones(self.sys.lat.sites, bool)
         ax.set_ylim([-en_max, en_max])
     else:
         ind_en = np.argwhere((self.sys.en > lims[0])
                              & (self.sys.en < lims[1]))
         ind_en = np.ravel(ind_en)
         ax.set_xlim(lims)
     en = self.sys.en[ind_en]
     n, bins, patches = plt.hist(en, bins=nbr_bins, color='b', alpha=0.8)
     ax.set_title('Spectrum', fontsize=fs)
     ax.set_xlabel('$E$', fontsize=fs)
     ax.set_ylabel('number of states', fontsize=fs)
     ax.set_ylim([0, np.max(n) + 1])
     for label in ax.xaxis.get_majorticklabels():
         label.set_fontsize(fs)
     for label in ax.yaxis.get_majorticklabels():
         label.set_fontsize(fs)
Ejemplo n.º 5
0
    def get_animation(self, s=300., fs=20., prop_type='real', figsize=None):
        '''
        Get time evolution animation.

        :param s: Default value 300. Circle size.
        :param fs: Default value 20. Fontsize.
        :param figsize: Tuple. Default value None. Figsize.
        :param prop_type: Default value None. Figsize.

        :returns:
          * **ani** -- Animation.
        '''
        error_handling.empty_ndarray(self.prop, 'get_propagation or get_pumping')
        error_handling.positive_real(s, 's')
        error_handling.positive_real(fs, 'fs')
        error_handling.prop_type(prop_type)
        error_handling.tuple_2elem(figsize, 'figsize')
        if os.name == 'posix':
            blit = False
        else:
            blit = True
        if prop_type == 'real':
            color = self.prop.real
            max_val = max(np.max(color), -np.min(color))
            ticks = [-max_val, max_val]
            cmap = 'seismic'
        elif prop_type == 'imag':
            color = self.prop.imag
            max_val = max(np.max(color), -np.min(color))
            ticks = [-max_val, max_val]
            cmap = 'seismic'
        else:
            color = np.abs(self.prop) ** 2
            ticks = [0., np.max(color)]
            cmap = 'Reds'
        fig, ax = plt.subplots(figsize=figsize)
        plt.xlim([self.lat.coor['x'][0]-1., self.lat.coor['x'][-1]+1.])
        plt.ylim([self.lat.coor['y'][0]-1., self.lat.coor['y'][-1]+1.])
        scat = plt.scatter(self.lat.coor['x'], self.lat.coor['y'], c=color[:, 0],
                                   s=s, vmin=ticks[0], vmax=ticks[1],
                                   cmap=plt.get_cmap(cmap))
        frame = plt.gca()
        frame.axes.get_xaxis().set_ticks([])
        frame.axes.get_yaxis().set_ticks([])
        ax.set_aspect('equal')
        if prop_type == 'norm':
            cbar = fig.colorbar(scat, ticks=ticks)
            cbar.ax.set_yticklabels(['0','max'])
        else:
            cbar = fig.colorbar(scat, ticks=[ticks[0], 0, ticks[1]])
            cbar.ax.set_yticklabels(['min', '0','max'])

        def update(i, color, scat):
            scat.set_array(color[:, i])
            return scat,

        ani = animation.FuncAnimation(fig, update, frames=self.steps,
                                                  fargs=(color, scat), blit=blit, repeat=False)
        return ani
Ejemplo n.º 6
0
    def intensity_disk(self,
                       intensity,
                       s=200.,
                       fs=20.,
                       lims=None,
                       figsize=None,
                       title=r'$|\psi|^2$'):
        '''
        Plot the intensity. Colormap with identical disk shape.

        :param intensity: np.array.Field intensity.
        :param s: Default value 200. Disk size.
        :param fs: Default value 20. Font size.
        :param lims: List. Default value None. Colormap limits.
        :param figsize: Tuple. Default value None. Figure size.
        :param title: String. Default value '$|\psi_n|^2$'. Title.

        :returns:
            * **fig** -- Figure.
        '''
        error_handling.empty_ndarray(self.sys.lat.coor, 'sys.get_lattice')
        error_handling.ndarray(intensity, 'intensity', self.sys.lat.sites)
        error_handling.positive_real(s, 's')
        error_handling.positive_real(fs, 'fs')
        error_handling.tuple_2elem(figsize, 'figsize')
        error_handling.string(title, 'title')
        fig, ax = plt.subplots(figsize=figsize)
        plt.title(title, fontsize=fs + 5)
        map_red = plt.get_cmap('Reds')
        if lims is None:
            lims = [0., np.max(intensity)]
            y_ticks = ['0', 'max']
        else:
            y_ticks = lims
        plt.scatter(self.sys.lat.coor['x'],
                    self.sys.lat.coor['y'],
                    c=intensity,
                    s=s,
                    cmap=map_red,
                    vmin=lims[0],
                    vmax=lims[1])
        cbar = plt.colorbar(ticks=lims)
        ax.set_xticks([])
        ax.set_yticks([])
        ax.set_xlim(
            np.min(self.sys.lat.coor['x']) - 1.,
            np.max(self.sys.lat.coor['x']) + 1.)
        ax.set_ylim(
            np.min(self.sys.lat.coor['y']) - 1.,
            np.max(self.sys.lat.coor['y']) + 1.)
        cbar.ax.set_yticklabels([y_ticks[0], y_ticks[1]])
        cbar.ax.tick_params(labelsize=fs)
        ax.set_aspect('equal')
        fig.set_tight_layout(True)
        plt.draw()
        return fig
Ejemplo n.º 7
0
    def polarization(self,
                     fig=None,
                     ax1=None,
                     ms=10.,
                     fs=20.,
                     lims=None,
                     tag_pola=None,
                     ind=None):
        '''
        Plot sublattice polarization.

        :param fig: Figure. Default value None. (used by the method spectrum).
        :param ax1: Axis. Default value None. (used by the method spectrum).
        :param ms: Positive Float. Default value 10. Markersize.
        :param fs: Positive Float. Default value 20. Fontsize.
        :param lims: List, lims[0] energy min, lims[1] energy max.
        :param tag_pola: Binary char. Default value None. Tag of the sublattice.
        :param ind: List. Default value None. List of indices. (used in the method spectrum).

        :returns:
            * **fig** -- Figure.
        '''
        if fig is None:
            error_handling.sys(self.sys)
            error_handling.empty_ndarray(self.sys.en, 'sys.get_eig')
            error_handling.positive_real(ms, 'ms')
            error_handling.positive_real(fs, 'fs')
            error_handling.lims(lims)
            fig, ax2 = plt.subplots()
            ax2 = plt.gca()
            if lims is None:
                ax2.set_ylim([-0.1, 1.1])
                ind = np.ones(self.sys.lat.sites, bool)
            else:
                ind = (self.sys.en > lims[0]) & (self.sys.en < lims[1])
                ax2.set_ylim([lims[0] - 0.1, lims[1] + 0.1])
        else:
            ax2 = plt.twinx()
        error_handling.empty_ndarray(self.sys.pola, 'sys.get_pola')
        error_handling.tag(tag_pola, self.sys.lat.tags)
        x = np.arange(self.sys.lat.sites)
        i_tag = self.sys.lat.tags == tag_pola
        ax2.plot(x[ind],
                 np.ravel(self.sys.pola[ind, i_tag]),
                 'or',
                 markersize=(4 * ms) // 5)
        str_tag = tag_pola.decode('ascii')
        ylabel = '$<' + str_tag.upper() + '|' + str_tag.upper() + '>$'
        ax2.set_ylabel(ylabel, fontsize=fs, color='red')
        ax2.set_ylim([-0.1, 1.1])
        ax2.set_xlim(-0.5, x[ind][-1] + 0.5)
        for tick in ax2.xaxis.get_major_ticks():
            tick.label.set_fontsize(fs)
        for label in ax2.get_yticklabels():
            label.set_color('r')
        return fig, ax2
Ejemplo n.º 8
0
    def get_ipr(self):
        r'''
        Get the Inverse Participation Ratio: 

        .. math:: 

            IPR_n = |\sum_i\psi_i^{n}|^4\, .
        '''
        error_handling.empty_ndarray(self.rn, 'sys.get_eig(eigenvec=True)')
        self.ipr = np.sum(self.intensity**2, axis=0)
Ejemplo n.º 9
0
Archivo: system.py Proyecto: cpoli/tbee
    def get_ipr(self):
        r'''
        Get the Inverse Participation Ratio: 

        .. math:: 

            IPR_n = |\sum_i\psi_i^{n}|^4\, .
        '''
        error_handling.empty_ndarray(self.rn, 'sys.get_eig(eigenvec=True)')
        self.ipr = np.sum(self.intensity ** 2, axis=0)
Ejemplo n.º 10
0
Archivo: plot.py Proyecto: cpoli/tbee
    def spectrum(self, ms=10, fs=20, lims=None, 
                          tag_pola=None, ipr=None, peterman=None):
        '''
        Plot spectrum (eigenenergies real part (blue circles),
        and sublattice polarization if *pola* not empty (red circles).

        :param ms: Default value 10. Markersize.
        :param fs: Default value 20. Fontsize.
        :param lims: List, lims[0] energy min, lims[1] energy max.
        :param tag_pola: Default value None. Binary char. Tag of the sublattice.
        :param ipr: Default value None. If True plot the Inverse Partitipation Ration.
        :param petermann: Default value None. If True plot the Petermann factor.

        :returns:
            * **fig** -- Figure.
        '''
        error_handling.empty_ndarray(self.sys.en, 'sys.get_eig')
        error_handling.positive_real(ms, 'ms')
        error_handling.positive_real(fs, 'fs')
        error_handling.lims(lims)
        fig, ax1 = plt.subplots()
        ax1 = plt.gca()
        x = np.arange(self.sys.lat.sites)
        if lims is None:
            en_max = np.max(self.sys.en.real)
            ax1.set_ylim([-en_max-0.2, en_max+0.2])
            ind = np.ones(self.sys.lat.sites, bool)
        else:
            ind = (self.sys.en > lims[0]) & (self.sys.en < lims[1])
            ax1.set_ylim([lims[0]-0.1, lims[1]+0.1])
        ax1.plot(x[ind], self.sys.en.real[ind], 'ob', markersize=ms)
        ax1.set_title('Spectrum', fontsize=fs)
        ax1.set_xlabel('$n$', fontsize=fs)
        ax1.set_ylabel('$E_n$', fontsize=fs, color='blue')
        for label in ax1.get_yticklabels():
            label.set_color('b')
        if tag_pola:
            error_handling.tag(tag_pola, self.sys.lat.tags)
            fig, ax2 = self.polarization(fig=fig, ax1=ax1, ms=ms, fs=fs, tag_pola=tag_pola, ind=ind)
        elif ipr:
            fig, ax2 = self.ipr(fig=fig, ax1=ax1, ms=ms, fs=fs, ind=ind)
        elif peterman:
            fig, ax2 = self.petermann(fig=fig, ax1=ax1, ms=ms, fs=fs, ind=ind)
        for label in ax1.xaxis.get_majorticklabels():
            label.set_fontsize(fs)
        for label in ax1.yaxis.get_majorticklabels():
            label.set_fontsize(fs)
        xa = ax1.get_xaxis()
        ax1.set_xlim([x[ind][0]-0.5, x[ind][-1]+0.5])
        xa.set_major_locator(plt.MaxNLocator(integer=True))
        fig.set_tight_layout(True)
        plt.draw()
        return fig
Ejemplo n.º 11
0
Archivo: system.py Proyecto: cpoli/tbee
    def get_intensity_pola_min(self, tag_pola):
        '''
        Get the state with smallest polarization on one sublattice.

        :param tag_pola: Binary char. Sublattice tag.

        :returns:
            * **intensity** -- Intensity of max polarized state on *tag*.
        '''
        error_handling.empty_ndarray(self.rn, 'sys.get_eig(eigenvec=True)')
        error_handling.tag(tag_pola, self.lat.tags)
        i_tag = self.lat.tags == tag_pola
        ind = np.argmin(self.pola[:, i_tag])
        print('State with polarization: {:.5f}'.format(float(self.pola[ind, i_tag])))
        return self.intensity[:, ind]
Ejemplo n.º 12
0
 def lattice_generic(self, coor, ms, lw, c, fs, axis, plt_hop, plt_hop_low,
                     plt_index, figsize):
     '''
     Private method called by *lattice* and *lattice_hop*.
     '''
     error_handling.positive_real(ms, 'ms')
     error_handling.positive_real(lw, 'lw')
     error_handling.positive_real(c, 'c')
     error_handling.positive_real(fs, 'fs')
     error_handling.boolean(axis, 'axis')
     error_handling.boolean(plt_hop, 'plt_hop')
     error_handling.boolean(plt_hop_low, 'plt_hop_low')
     error_handling.boolean(plt_index, 'plt_index')
     error_handling.tuple_2elem(figsize, 'figsize')
     fig, ax = plt.subplots(figsize=figsize)
     # hoppings
     if plt_hop:
         error_handling.empty_ndarray(self.sys.hop, 'sys.hop')
         self.plt_hopping(coor, self.sys.hop[self.sys.hop['ang'] >= 0], c)
     if plt_hop_low:
         error_handling.empty_ndarray(self.sys.hop, 'sys.hop')
         self.plt_hopping(coor, self.sys.hop[self.sys.hop['ang'] < 0], c)
     # plot sites
     for color, tag in zip(self.colors, self.sys.lat.tags):
         plt.plot(coor['x'][coor['tag'] == tag],
                  coor['y'][coor['tag'] == tag],
                  'o',
                  color=color,
                  ms=ms,
                  markeredgecolor='none')
     ax.set_aspect('equal')
     ax.set_xlim([np.min(coor['x']) - 1., np.max(coor['x']) + 1.])
     ax.set_ylim([np.min(coor['y']) - 1., np.max(coor['y']) + 1.])
     if not axis:
         ax.axis('off')
     # plot indices
     if plt_index:
         indices = ['{}'.format(i) for i in range(self.sys.lat.sites)]
         for l, x, y in zip(indices, coor['x'], coor['y']):
             plt.annotate(l,
                          xy=(x, y),
                          xytext=(0, 0),
                          textcoords='offset points',
                          ha='right',
                          va='bottom',
                          size=fs)
     plt.draw()
     return fig
Ejemplo n.º 13
0
Archivo: plot.py Proyecto: cpoli/tbee
    def intensity_area(self, intensity, s=1000., lw=1., fs=20., plt_hop=False,
                                  figsize=None, title=r'$|\psi|^2$'):
        '''
        Plot the intensity. Intensity propotional to disk shape.

        :param intensity: np.array. Intensity.
        :param s: Positive Float. Default value 1000. 
            Circle size given by s * intensity.
        :param lw: Positive Float. Default value 1. Hopping linewidths.
        :param fs: Positive Float. Default value 20. Fontsize.
        :param plt_hop: Boolean. Default value False. Plot hoppings.
        :param figsize: Tuple. Default value None. Figure size.
        :param title: String. Default value '$|\psi_{ij}|^2$'. Figure title.

        :returns:
            * **fig** -- Figure.
        '''
        error_handling.empty_ndarray(self.sys.lat.coor, 'sys.get_lattice')
        error_handling.ndarray(intensity, 'intensity', self.sys.lat.sites)
        error_handling.positive_real(s, 's')
        error_handling.positive_real(fs, 'fs')
        error_handling.boolean(plt_hop, 'plt_hop')
        error_handling.tuple_2elem(figsize, 'figsize')
        error_handling.string(title, 'title')
        fig, ax = plt.subplots()
        ax.set_xlabel('$i$', fontsize=fs)
        ax.set_ylabel('$j$', fontsize=fs)
        ax.set_title(title, fontsize=fs)
        if plt_hop:
            plt.plot([self.sys.lat.coor['x'][self.sys.hop['i'][:]], 
                             self.sys.lat.coor['x'][self.sys.hop['j'][:]]],
                            [self.sys.lat.coor['y'][self.sys.hop['i'][:]],
                             self.sys.lat.coor['y'][self.sys.hop['j'][:]]],
                            'k', lw=lw)
        for tag, color in zip(self.sys.lat.tags, self.colors):
            plt.scatter(self.sys.lat.coor['x'][self.sys.lat.coor['tag'] == tag],
                        self.sys.lat.coor['y'][self.sys.lat.coor['tag'] == tag],
                        s=100*s*intensity[self.sys.lat.coor['tag'] == tag],
                        c=color, alpha=0.5)
        ax.set_aspect('equal')
        ax.axis('off')
        x_lim = [np.min(self.sys.lat.coor['x'])-2., np.max(self.sys.lat.coor['x'])+2.]
        y_lim = [np.min(self.sys.lat.coor['y'])-2., np.max(self.sys.lat.coor['y'])+2.]
        ax.set_xlim(x_lim)
        ax.set_ylim(y_lim)
        fig.set_tight_layout(True)
        plt.draw()
        return fig
Ejemplo n.º 14
0
    def get_intensity_pola_min(self, tag_pola):
        '''
        Get the state with smallest polarization on one sublattice.

        :param tag_pola: Binary char. Sublattice tag.

        :returns:
            * **intensity** -- Intensity of max polarized state on *tag*.
        '''
        error_handling.empty_ndarray(self.rn, 'sys.get_eig(eigenvec=True)')
        error_handling.tag(tag_pola, self.lat.tags)
        i_tag = self.lat.tags == tag_pola
        ind = np.argmin(self.pola[:, i_tag])
        print('State with polarization: {:.5f}'.format(
            float(self.pola[ind, i_tag])))
        return self.intensity[:, ind]
Ejemplo n.º 15
0
    def get_intensity_en(self, lims):
        '''
        Get, if any, the intensity of the sum of the states 
        between *lims[0]* and *lims[1]*.

        :param lims: List. lims[0] energy min, lims[1] energy max.

        :returns:
            * **intensity** -- Sum of the intensities between (lims[0], lims[1]).
        '''
        error_handling.empty_ndarray(self.rn, 'sys.get_eig(eigenvec=True)')
        error_handling.lims(lims)
        ind = np.where((self.en > lims[0]) & (self.en < lims[1]))
        ind = np.ravel(ind)
        print('{} states between {} and {}'.format(len(ind), lims[0], lims[1]))
        return np.sum(self.intensity[:, ind], axis=1)
Ejemplo n.º 16
0
Archivo: system.py Proyecto: cpoli/tbee
    def get_intensity_en(self, lims):
        '''
        Get, if any, the intensity of the sum of the states 
        between *lims[0]* and *lims[1]*.

        :param lims: List. lims[0] energy min, lims[1] energy max.

        :returns:
            * **intensity** -- Sum of the intensities between (lims[0], lims[1]).
        '''
        error_handling.empty_ndarray(self.rn, 'sys.get_eig(eigenvec=True)')
        error_handling.lims(lims)
        ind = np.where((self.en > lims[0]) & (self.en < lims[1]))
        ind = np.ravel(ind)
        print('{} states between {} and {}'.format(len(ind), lims[0], lims[1]))
        return np.sum(self.intensity[:, ind], axis=1)
Ejemplo n.º 17
0
Archivo: plot.py Proyecto: cpoli/tbee
    def polarization(self, fig=None, ax1=None, ms=10., fs=20., lims=None,
                              tag_pola=None, ind=None):
        '''
        Plot sublattice polarization.

        :param fig: Figure. Default value None. (used by the method spectrum).
        :param ax1: Axis. Default value None. (used by the method spectrum).
        :param ms: Positive Float. Default value 10. Markersize.
        :param fs: Positive Float. Default value 20. Fontsize.
        :param lims: List, lims[0] energy min, lims[1] energy max.
        :param tag_pola: Binary char. Default value None. Tag of the sublattice.
        :param ind: List. Default value None. List of indices. (used in the method spectrum).

        :returns:
            * **fig** -- Figure.
        '''
        if fig is None:
            error_handling.sys(self.sys)
            error_handling.empty_ndarray(self.sys.en, 'sys.get_eig')
            error_handling.positive_real(ms, 'ms')
            error_handling.positive_real(fs, 'fs')
            error_handling.lims(lims)
            fig, ax2 = plt.subplots()
            ax2 = plt.gca()
            if lims is None:
                ax2.set_ylim([-0.1, 1.1])
                ind = np.ones(self.sys.lat.sites, bool)
            else:
                ind = (self.sys.en > lims[0]) & (self.sys.en < lims[1])
                ax2.set_ylim([lims[0]-0.1, lims[1]+0.1])
        else:
            ax2 = plt.twinx()
        error_handling.empty_ndarray(self.sys.pola, 'sys.get_pola')
        error_handling.tag(tag_pola, self.sys.lat.tags)
        x = np.arange(self.sys.lat.sites)
        i_tag = self.sys.lat.tags == tag_pola
        ax2.plot(x[ind], np.ravel(self.sys.pola[ind, i_tag]), 'or', markersize=(4*ms)//5)
        str_tag = tag_pola.decode('ascii')
        ylabel = '$<' + str_tag.upper() + '|' + str_tag.upper() + '>$'
        ax2.set_ylabel(ylabel, fontsize=fs, color='red')
        ax2.set_ylim([-0.1, 1.1])
        ax2.set_xlim(-0.5, x[ind][-1]+0.5)
        for tick in ax2.xaxis.get_major_ticks():
            tick.label.set_fontsize(fs)
        for label in ax2.get_yticklabels():
            label.set_color('r')
        return fig, ax2
Ejemplo n.º 18
0
    def plt_propagation_1d(self, prop_type="real", fs=20, figsize=None):
        """
        Plot time evolution for 1D systems. 

        :param fs: Default value 20. Fontsize.
        """
        error_handling.empty_ndarray(self.prop, "get_propagation or get_pumping")
        error_handling.positive_real(fs, "fs")
        error_handling.prop_type(prop_type)
        error_handling.tuple_2elem(figsize, "figsize")
        fig, ax = plt.subplots(figsize=figsize)
        plt.ylabel("n", fontsize=fs)
        plt.xlabel("z", fontsize=fs)
        if prop_type == "real":
            color = self.prop_smooth_1d(self.prop.real)
            max_val = max(np.max(color), -np.min(color))
            ticks = [-max_val, max_val]
            cmap = "seismic"
        elif prop_type == "imag":
            color = self.prop_smooth_1d(self.prop.imag)
            max_val = max(np.max(color), -np.min(color))
            ticks = [-max_val, max_val]
            cmap = "seismic"
        else:
            color = self.prop_smooth_1d(np.abs(self.prop) ** 2)
            ticks = [0.0, np.max(color[:, -1])]
            cmap = plt.cm.hot
        extent = (-0, self.steps * self.dz, self.lat.sites - 0.5, -0.5)
        aspect = "auto"
        interpolation = "nearest"
        im = plt.imshow(
            color, cmap=cmap, aspect=aspect, interpolation=interpolation, extent=extent, vmin=ticks[0], vmax=ticks[-1]
        )
        for label in ax.xaxis.get_majorticklabels():
            label.set_fontsize(fs)
        for label in ax.yaxis.get_majorticklabels():
            label.set_fontsize(fs)
        ax.get_yaxis().set_major_locator(plt.MaxNLocator(integer=True))
        if prop_type == "norm":
            cbar = fig.colorbar(im, ticks=ticks)
            cbar.ax.set_yticklabels(["0", "max"])
        else:
            cbar = fig.colorbar(im, ticks=[ticks[0], 0, ticks[1]])
            cbar.ax.set_yticklabels(["min", "0", "max"])
        cbar.ax.tick_params(labelsize=fs)
        return fig
Ejemplo n.º 19
0
    def plt_propagation_1d(self, prop_type='real', fs=20, figsize=None):
        '''
        Plot time evolution for 1D systems. 

        :param fs: Default value 20. Fontsize.
        '''
        error_handling.empty_ndarray(self.prop, 'get_propagation or get_pumping')
        error_handling.positive_real(fs, 'fs')
        error_handling.prop_type(prop_type)
        error_handling.tuple_2elem(figsize, 'figsize')
        fig, ax = plt.subplots(figsize=figsize)
        plt.ylabel('n', fontsize=fs)
        plt.xlabel('z', fontsize=fs)
        if prop_type == 'real':
            color = self.prop_smooth_1d(self.prop.real)
            max_val = max(np.max(color), -np.min(color))
            ticks = [-max_val, max_val]
            cmap = 'seismic'
        elif prop_type == 'imag':
            color = self.prop_smooth_1d(self.prop.imag)
            max_val = max(np.max(color), -np.min(color))
            ticks = [-max_val, max_val]
            cmap = 'seismic'
        else:
            color = self.prop_smooth_1d(np.abs(self.prop) ** 2)
            ticks = [0., np.max(color[:, -1])]
            cmap = plt.cm.hot
        extent = (-0, self.steps*self.dz, self.lat.sites-.5, -.5)
        aspect = 'auto'
        interpolation = 'nearest'
        im = plt.imshow(color, cmap=cmap, aspect=aspect,
                                  interpolation=interpolation, extent=extent,
                                  vmin=ticks[0], vmax=ticks[-1])
        for label in ax.xaxis.get_majorticklabels():
            label.set_fontsize(fs)
        for label in ax.yaxis.get_majorticklabels():
            label.set_fontsize(fs)
        ax.get_yaxis().set_major_locator(plt.MaxNLocator(integer=True))
        if prop_type == 'norm':
            cbar = fig.colorbar(im, ticks=ticks)
            cbar.ax.set_yticklabels(['0','max'])
        else:
            cbar = fig.colorbar(im, ticks=[ticks[0], 0, ticks[1]])
            cbar.ax.set_yticklabels(['min', '0','max'])
        cbar.ax.tick_params(labelsize=fs)
        return fig
Ejemplo n.º 20
0
Archivo: system.py Proyecto: cpoli/tbee
    def get_petermann(self):
        r'''
        Get the Petermann factor: 
        
        .. math::

            K_n = \frac{\langle\psi_L^{n}|\psi_L^{n}\rangle\langle\psi_R^{n}|\psi_R^{n}\rangle}{\langle\psi_L^{n}|\psi_R^{n}\rangle}\, .

        .. note::

            LA.eig fixes the norm such that :math:`\langle\psi_L^{n}|\psi_L^{n}\rangle = 1` and :math:`\langle\psi_R^{n}|\psi_R^{n}\rangle = 1`.
        '''
        if not (self.ham.H != self.ham).nnz:
            self.petermann = np.ones(self.lat.sites)
            return
        error_handling.empty_ndarray(self.ln, 'sys.get_eig(eigenvec=True, left=True)')
        left_right = np.sum(self.ln * np.conjugate(self.rn), axis=0).real
        self.petermann = 1. / left_right ** 2
Ejemplo n.º 21
0
    def get_petermann(self):
        r'''
        Get the Petermann factor: 
        
        .. math::

            K_n = \frac{\langle\psi_L^{n}|\psi_L^{n}\rangle\langle\psi_R^{n}|\psi_R^{n}\rangle}{\langle\psi_L^{n}|\psi_R^{n}\rangle}\, .

        .. note::

            LA.eig fixes the norm such that :math:`\langle\psi_L^{n}|\psi_L^{n}\rangle = 1` and :math:`\langle\psi_R^{n}|\psi_R^{n}\rangle = 1`.
        '''
        if not (self.ham.H != self.ham).nnz:
            self.petermann = np.ones(self.lat.sites)
            return
        error_handling.empty_ndarray(self.ln,
                                     'sys.get_eig(eigenvec=True, left=True)')
        left_right = np.sum(self.ln * np.conjugate(self.rn), axis=0).real
        self.petermann = 1. / left_right**2
Ejemplo n.º 22
0
Archivo: plot.py Proyecto: cpoli/tbee
    def intensity_disk(self, intensity, s=200., fs=20., lims=None, figsize=None, 
                                 title=r'$|\psi|^2$'):
        '''
        Plot the intensity. Colormap with identical disk shape.

        :param intensity: np.array.Field intensity.
        :param s: Default value 200. Disk size.
        :param fs: Default value 20. Font size.
        :param lims: List. Default value None. Colormap limits.
        :param figsize: Tuple. Default value None. Figure size.
        :param title: String. Default value '$|\psi_n|^2$'. Title.

        :returns:
            * **fig** -- Figure.
        '''
        error_handling.empty_ndarray(self.sys.lat.coor, 'sys.get_lattice')
        error_handling.ndarray(intensity, 'intensity', self.sys.lat.sites)
        error_handling.positive_real(s, 's')
        error_handling.positive_real(fs, 'fs')
        error_handling.tuple_2elem(figsize, 'figsize')
        error_handling.string(title, 'title')
        fig, ax = plt.subplots(figsize=figsize)
        plt.title(title, fontsize=fs+5)
        map_red = plt.get_cmap('Reds')
        if lims is None:
            lims = [0., np.max(intensity)]
            y_ticks = ['0', 'max']
        else:
            y_ticks = lims
        plt.scatter(self.sys.lat.coor['x'], self.sys.lat.coor['y'], c=intensity, s=s,
                         cmap=map_red, vmin=lims[0], vmax=lims[1])
        cbar = plt.colorbar(ticks=lims)
        ax.set_xticks([])
        ax.set_yticks([])
        ax.set_xlim(np.min(self.sys.lat.coor['x'])-1., np.max(self.sys.lat.coor['x'])+1.)
        ax.set_ylim(np.min(self.sys.lat.coor['y'])-1., np.max(self.sys.lat.coor['y'])+1.)
        cbar.ax.set_yticklabels([y_ticks[0], y_ticks[1]])
        cbar.ax.tick_params(labelsize=fs)
        ax.set_aspect('equal')
        fig.set_tight_layout(True)
        plt.draw()
        return fig
Ejemplo n.º 23
0
Archivo: plot.py Proyecto: cpoli/tbee
    def lattice_hop(self, ms=20, lw=5, c=3., fs=20, axis=False, plt_hop=False,
                            plt_hop_low=False, plt_index=False, figsize=None):
        '''
        Plot lattice in hopping space.

        :param ms: Positive Float. Default value 20. Markersize.
        :param c: Positive Float. Default value 3. Coefficient.
            Hopping linewidths given by c*hop['t'].
        :param fs: Positive Float. Default value 20. Fontsize.
        :param axis: Boolean. Default value False. Plot axis.
        :param plt_hop: Boolean. Default value False. Plot hoppings.
        :param plt_index: Boolean. Default value False. Plot site labels.
        :param figsize: Tuple. Default value None. Figure size.

        :returns:
            * **fig** -- Figure.
        '''
        error_handling.empty_ndarray(self.sys.coor_hop, 'sys.get_coor_hop')
        return self.lattice_generic(self.sys.coor_hop, ms, lw, c, fs, axis, plt_hop,
                                                 plt_hop_low, plt_index, figsize)
Ejemplo n.º 24
0
Archivo: plot.py Proyecto: cpoli/tbee
    def spectrum_complex(self, ms=10., fs=20., lims=None):
        '''
        Plot complex value eigenenergies, real part (blue circles),
        and imaginary part (red circles).

        :param ms: Positive Float. Default value 20. Markersize.
        :param fs: Positive Float. Default value 20. Font size.
        :param lims: List. lims[0] energy min, lims[1] energy max.

        :returns:
            * **fig** -- Figure.
        '''
        error_handling.empty_ndarray(self.sys.en, 'sys.get_eig')
        error_handling.positive_real(ms, 'ms')
        error_handling.positive_real(fs, 'fs')
        error_handling.lims(lims)
        fig, ax1 = plt.subplots()
        ax1 = plt.gca()
        x = np.arange(self.sys.lat.sites)
        if lims is None:
            en_max = np.max(self.sys.en.real)
            ax1.set_ylim([-en_max-0.2, en_max+0.2])
            ind = np.ones(self.sys.lat.sites, bool)
        else:
            ind = (self.sys.en > lims[0]) & (self.sys.en < lims[1])
            ax1.set_ylim([lims[0]-0.1, lims[1]+0.1])
        ax1.plot(x[ind], self.sys.en.real[ind], 'ob', markersize=ms)
        ax1.plot(x[ind], self.sys.en.imag[ind], 'or', markersize=ms)
        ax1.set_title('Spectrum', fontsize=fs)
        ax1.set_xlabel('$n$', fontsize=fs)
        ax1.set_ylabel('Re '+r'$E_n$'+',    Im '+r'$E_n$', fontsize=fs)
        for label in ax1.xaxis.get_majorticklabels():
            label.set_fontsize(fs)
        for label in ax1.yaxis.get_majorticklabels():
            label.set_fontsize(fs)
        xa = ax1.get_xaxis()
        ax1.set_xlim([x[ind][0]-0.1, x[ind][-1]+0.1])
        xa.set_major_locator(plt.MaxNLocator(integer=True))
        fig.set_tight_layout(True)
        plt.draw()
        return fig
Ejemplo n.º 25
0
Archivo: plot.py Proyecto: cpoli/tbee
 def lattice_generic(self, coor, ms, lw, c, fs, axis, plt_hop,
                               plt_hop_low, plt_index, figsize):
     '''
     Private method called by *lattice* and *lattice_hop*.
     '''
     error_handling.positive_real(ms, 'ms')
     error_handling.positive_real(lw, 'lw')
     error_handling.positive_real(c, 'c')
     error_handling.positive_real(fs, 'fs')
     error_handling.boolean(axis, 'axis')
     error_handling.boolean(plt_hop, 'plt_hop')
     error_handling.boolean(plt_hop_low, 'plt_hop_low')
     error_handling.boolean(plt_index, 'plt_index')
     error_handling.tuple_2elem(figsize, 'figsize')
     fig, ax = plt.subplots(figsize=figsize)
     # hoppings
     if plt_hop:
         error_handling.empty_ndarray(self.sys.hop, 'sys.hop')
         self.plt_hopping(coor, self.sys.hop[self.sys.hop['ang']>=0], c)
     if plt_hop_low:
         error_handling.empty_ndarray(self.sys.hop, 'sys.hop')
         self.plt_hopping(coor, self.sys.hop[self.sys.hop['ang']<0], c)
     # plot sites
     for color, tag in zip(self.colors, self.sys.lat.tags):
         plt.plot(coor['x'][coor['tag'] == tag],
                    coor['y'][coor['tag'] == tag],
                    'o', color=color, ms=ms, markeredgecolor='none')
     ax.set_aspect('equal')
     ax.set_xlim([np.min(coor['x'])-1., np.max(coor['x'])+1.])
     ax.set_ylim([np.min(coor['y'])-1., np.max(coor['y'])+1.])
     if not axis:
         ax.axis('off')
     # plot indices
     if plt_index:
         indices = ['{}'.format(i) for i in range(self.sys.lat.sites)]
         for l, x, y in zip(indices, coor['x'], coor['y']):
             plt.annotate(l, xy=(x, y), xytext=(0, 0),
                                 textcoords='offset points',
                                 ha='right', va='bottom', size=fs)
     plt.draw()
     return fig
Ejemplo n.º 26
0
    def spectrum_complex(self, ms=10., fs=20., lims=None):
        '''
        Plot complex value eigenenergies, real part (blue circles),
        and imaginary part (red circles).

        :param ms: Positive Float. Default value 20. Markersize.
        :param fs: Positive Float. Default value 20. Font size.
        :param lims: List. lims[0] energy min, lims[1] energy max.

        :returns:
            * **fig** -- Figure.
        '''
        error_handling.empty_ndarray(self.sys.en, 'sys.get_eig')
        error_handling.positive_real(ms, 'ms')
        error_handling.positive_real(fs, 'fs')
        error_handling.lims(lims)
        fig, ax1 = plt.subplots()
        ax1 = plt.gca()
        x = np.arange(self.sys.lat.sites)
        if lims is None:
            en_max = np.max(self.sys.en.real)
            ax1.set_ylim([-en_max - 0.2, en_max + 0.2])
            ind = np.ones(self.sys.lat.sites, bool)
        else:
            ind = (self.sys.en > lims[0]) & (self.sys.en < lims[1])
            ax1.set_ylim([lims[0] - 0.1, lims[1] + 0.1])
        ax1.plot(x[ind], self.sys.en.real[ind], 'ob', markersize=ms)
        ax1.plot(x[ind], self.sys.en.imag[ind], 'or', markersize=ms)
        ax1.set_title('Spectrum', fontsize=fs)
        ax1.set_xlabel('$n$', fontsize=fs)
        ax1.set_ylabel('Re ' + r'$E_n$' + ',    Im ' + r'$E_n$', fontsize=fs)
        for label in ax1.xaxis.get_majorticklabels():
            label.set_fontsize(fs)
        for label in ax1.yaxis.get_majorticklabels():
            label.set_fontsize(fs)
        xa = ax1.get_xaxis()
        ax1.set_xlim([x[ind][0] - 0.1, x[ind][-1] + 0.1])
        xa.set_major_locator(plt.MaxNLocator(integer=True))
        fig.set_tight_layout(True)
        plt.draw()
        return fig
Ejemplo n.º 27
0
    def petermann(self, fig=None, ax1=None, ms=10, fs=20, lims=None, ind=None):
        '''
        Plot Peterman factor.

        :param fig: Figure. Default value None. (used by the method spectrum).
        :param ax1: Axis. Default value None. (used by the method spectrum).
        :param ms: Positive Float. Default value 10. Markersize.
        :param fs: Positive Float. Default value 20. Fontsize.
        :param lims: List. lims[0] energy min, lims[1] energy max.
        :param ind: List. Default value None. List of indices. (used in the method spectrum).

        :returns:
            * **fig** -- Figure.
        '''
        if fig is None:
            error_handling.sys(self.sys)
            error_handling.empty_ndarray(self.sys.ipr, 'sys.get_petermann')
            error_handling.positive_real(ms, 'ms')
            error_handling.positive_real(fs, 'fs')
            error_handling.lims(lims)
            fig, ax2 = plt.subplots()
            ax2 = plt.gca()
            if lims is None:
                ind = np.ones(self.sys.lat.sites, bool)
            else:
                ind = (self.sys.en > lims[0]) & (self.sys.en < lims[1])
        else:
            ax2 = plt.twinx()
        error_handling.empty_ndarray(self.sys.ipr, 'sys.get_ipr')
        x = np.arange(self.sys.lat.sites)
        ax2.plot(x[ind],
                 self.sys.petermann[ind],
                 'or',
                 markersize=(4 * ms) // 5)
        ax2.set_ylabel('K', fontsize=fs, color='red')
        ax2.set_xlim(-0.5, x[ind][-1] + 0.5)
        for tick in ax2.xaxis.get_major_ticks():
            tick.label.set_fontsize(fs)
        for label in ax2.get_yticklabels():
            label.set_color('r')
        return fig, ax2
Ejemplo n.º 28
0
Archivo: plot.py Proyecto: cpoli/tbee
    def petermann(self, fig=None, ax1=None, ms=10, fs=20, lims=None, ind=None):
        '''
        Plot Peterman factor.

        :param fig: Figure. Default value None. (used by the method spectrum).
        :param ax1: Axis. Default value None. (used by the method spectrum).
        :param ms: Positive Float. Default value 10. Markersize.
        :param fs: Positive Float. Default value 20. Fontsize.
        :param lims: List. lims[0] energy min, lims[1] energy max.
        :param ind: List. Default value None. List of indices. (used in the method spectrum).

        :returns:
            * **fig** -- Figure.
        '''
        if fig is None:
            error_handling.sys(self.sys)
            error_handling.empty_ndarray(self.sys.ipr, 'sys.get_petermann')
            error_handling.positive_real(ms, 'ms')
            error_handling.positive_real(fs, 'fs')
            error_handling.lims(lims)
            fig, ax2 = plt.subplots()
            ax2 = plt.gca()
            if lims is None:
                ind = np.ones(self.sys.lat.sites, bool)
            else:
                ind = (self.sys.en > lims[0]) & (self.sys.en < lims[1])
        else:
            ax2 = plt.twinx()
        error_handling.empty_ndarray(self.sys.ipr, 'sys.get_ipr')
        x = np.arange(self.sys.lat.sites)
        ax2.plot(x[ind], self.sys.petermann[ind], 'or', markersize=(4*ms)//5)
        ax2.set_ylabel( 'K' , fontsize=fs, color='red')
        ax2.set_xlim(-0.5, x[ind][-1]+0.5)
        for tick in ax2.xaxis.get_major_ticks():
            tick.label.set_fontsize(fs)
        for label in ax2.get_yticklabels():
            label.set_color('r')
        return fig, ax2
Ejemplo n.º 29
0
    def intensity_1d(self,
                     intensity,
                     ms=20.,
                     lw=2.,
                     fs=20.,
                     title=r'$|\psi^{(j)}|^2$'):
        '''
        Plot intensity for 1D lattices.

        :param intensity: np.array. Field intensity.
        :param ms: Positive Float. Default value 20. Markersize.
        :param lw: Positive Float. Default value 2. Linewith, connect sublattice sites.
        :param fs: Positive Float. Default value 20. Font size.
        :param title: String. Default value 'Intensity'. Figure title.
        '''
        error_handling.ndarray(intensity, 'intensity', self.sys.lat.sites)
        error_handling.empty_ndarray(self.sys.lat.coor, 'sys.get_lattice')
        error_handling.positive_real(ms, 'ms')
        error_handling.positive_real(lw, 'lw')
        error_handling.positive_real(fs, 'fs')
        error_handling.string(title, 'title')
        fig, ax = plt.subplots()
        ax.set_xlabel('$j$', fontsize=fs)
        ax.set_ylabel(title, fontsize=fs)
        ax.set_title(title, fontsize=fs)
        for t, c in zip(self.sys.lat.tags, self.colors):
            plt.plot(self.sys.lat.coor['x'][self.sys.lat.coor['tag'] == t],
                     intensity[self.sys.lat.coor['tag'] == t],
                     '-o',
                     color=c,
                     ms=ms,
                     lw=lw)
        plt.xlim([-1., self.sys.lat.sites])
        plt.ylim([0., np.max(intensity) + .05])
        fig.set_tight_layout(True)
        plt.draw()
        return fig
Ejemplo n.º 30
0
    def spectrum(self,
                 ms=10,
                 fs=20,
                 lims=None,
                 tag_pola=None,
                 ipr=None,
                 peterman=None):
        '''
        Plot spectrum (eigenenergies real part (blue circles),
        and sublattice polarization if *pola* not empty (red circles).

        :param ms: Default value 10. Markersize.
        :param fs: Default value 20. Fontsize.
        :param lims: List, lims[0] energy min, lims[1] energy max.
        :param tag_pola: Default value None. Binary char. Tag of the sublattice.
        :param ipr: Default value None. If True plot the Inverse Partitipation Ration.
        :param petermann: Default value None. If True plot the Petermann factor.

        :returns:
            * **fig** -- Figure.
        '''
        error_handling.empty_ndarray(self.sys.en, 'sys.get_eig')
        error_handling.positive_real(ms, 'ms')
        error_handling.positive_real(fs, 'fs')
        error_handling.lims(lims)
        fig, ax1 = plt.subplots()
        ax1 = plt.gca()
        x = np.arange(self.sys.lat.sites)
        if lims is None:
            en_max = np.max(self.sys.en.real)
            ax1.set_ylim([-en_max - 0.2, en_max + 0.2])
            ind = np.ones(self.sys.lat.sites, bool)
        else:
            ind = (self.sys.en > lims[0]) & (self.sys.en < lims[1])
            ax1.set_ylim([lims[0] - 0.1, lims[1] + 0.1])
        ax1.plot(x[ind], self.sys.en.real[ind], 'ob', markersize=ms)
        ax1.set_title('Spectrum', fontsize=fs)
        ax1.set_xlabel('$n$', fontsize=fs)
        ax1.set_ylabel('$E_n$', fontsize=fs, color='blue')
        for label in ax1.get_yticklabels():
            label.set_color('b')
        if tag_pola:
            error_handling.tag(tag_pola, self.sys.lat.tags)
            fig, ax2 = self.polarization(fig=fig,
                                         ax1=ax1,
                                         ms=ms,
                                         fs=fs,
                                         tag_pola=tag_pola,
                                         ind=ind)
        elif ipr:
            fig, ax2 = self.ipr(fig=fig, ax1=ax1, ms=ms, fs=fs, ind=ind)
        elif peterman:
            fig, ax2 = self.petermann(fig=fig, ax1=ax1, ms=ms, fs=fs, ind=ind)
        for label in ax1.xaxis.get_majorticklabels():
            label.set_fontsize(fs)
        for label in ax1.yaxis.get_majorticklabels():
            label.set_fontsize(fs)
        xa = ax1.get_xaxis()
        ax1.set_xlim([x[ind][0] - 0.5, x[ind][-1] + 0.5])
        xa.set_major_locator(plt.MaxNLocator(integer=True))
        fig.set_tight_layout(True)
        plt.draw()
        return fig
Ejemplo n.º 31
0
    def get_animation_nb(self, s=300., fs=20., prop_type='real', figsize=None):
        '''
        Get time evolution animation for iPython notebooks.

        :param s: Default value 300. Circle shape.
        :param fs: Default value 20. Fontsize.

        :returns:
           * **ani** -- Animation.
        '''
        '''
        Get time evolution animation.

        :param s: Default value 300. Circle size.
        :param fs: Default value 20. Fontsize.
        :param figsize: Tuple. Default value None. Figsize.
        :param prop_type: Default value None. Figsize.

        :returns:
          * **ani** -- Animation.
        '''
        error_handling.empty_ndarray(self.prop, 'get_propagation or get_pumping')
        error_handling.positive_real(s, 's')
        error_handling.positive_real(fs, 'fs')
        error_handling.prop_type(prop_type)
        error_handling.tuple_2elem(figsize, 'figsize')
        if prop_type == 'real' or prop_type == 'imag':
            color = self.prop.real
            max_val = max(np.max(color[:, -1]), -np.min(color[:, -1]))
            ticks = [-max_val, max_val]
            cmap = 'seismic'
        else:
            color = np.abs(self.prop) ** 2
            ticks = [0., np.max(color)]
            cmap = 'Reds'
        fig = plt.figure()
        ax = plt.axes(xlim=(np.min(self.lat.coor['x']-.5), np.max(self.lat.coor['x']+.5)), 
                             ylim=(np.min(self.lat.coor['y']-.5), np.max(self.lat.coor['y']+.5)))
        ax.set_aspect('equal')
        frame = plt.gca()
        frame.axes.get_xaxis().set_ticks([])
        frame.axes.get_yaxis().set_ticks([])
        scat = plt.scatter(self.lat.coor['x'], self.lat.coor['y'], c=color[:, 0],
                                    s=s, vmin=ticks[0], vmax=ticks[1],
                                    cmap=cmap)
        if prop_type == 'real' or prop_type == 'imag':
            cbar = fig.colorbar(scat, ticks=[ticks[0], 0, ticks[1]])
            cbar.ax.set_yticklabels(['min', '0','max'])
        else:
            cbar = fig.colorbar(scat, ticks=[0, ticks[1]])
            cbar.ax.set_yticklabels(['0','max'])

        def init():
            scat.set_array(color[:, 0])
            return scat,

        def animate(i):
            scat.set_array(color[:, i])    
            return scat,

        return animation.FuncAnimation(fig, animate, init_func=init,
                                   frames=self.steps, interval=120, blit=True)
Ejemplo n.º 32
0
    def get_animation(self, s=300.0, fs=20.0, prop_type="real", figsize=None):
        """
        Get time evolution animation.

        :param s: Default value 300. Circle size.
        :param fs: Default value 20. Fontsize.
        :param figsize: Tuple. Default value None. Figsize.
        :param prop_type: Default value None. Figsize.

        :returns:
          * **ani** -- Animation.
        """
        error_handling.empty_ndarray(self.prop, "get_propagation or get_pumping")
        error_handling.positive_real(s, "s")
        error_handling.positive_real(fs, "fs")
        error_handling.prop_type(prop_type)
        error_handling.tuple_2elem(figsize, "figsize")
        if os.name == "posix":
            blit = False
        else:
            blit = True
        if prop_type == "real":
            color = self.prop.real
            max_val = max(np.max(color), -np.min(color))
            ticks = [-max_val, max_val]
            cmap = "seismic"
        elif prop_type == "imag":
            color = self.prop.imag
            max_val = max(np.max(color), -np.min(color))
            ticks = [-max_val, max_val]
            cmap = "seismic"
        else:
            color = np.abs(self.prop) ** 2
            ticks = [0.0, np.max(color)]
            cmap = "Reds"
        fig, ax = plt.subplots(figsize=figsize)
        plt.xlim([self.lat.coor["x"][0] - 1.0, self.lat.coor["x"][-1] + 1.0])
        plt.ylim([self.lat.coor["y"][0] - 1.0, self.lat.coor["y"][-1] + 1.0])
        scat = plt.scatter(
            self.lat.coor["x"],
            self.lat.coor["y"],
            c=color[:, 0],
            s=s,
            vmin=ticks[0],
            vmax=ticks[1],
            cmap=plt.get_cmap(cmap),
        )
        frame = plt.gca()
        frame.axes.get_xaxis().set_ticks([])
        frame.axes.get_yaxis().set_ticks([])
        ax.set_aspect("equal")
        if prop_type == "norm":
            cbar = fig.colorbar(scat, ticks=ticks)
            cbar.ax.set_yticklabels(["0", "max"])
        else:
            cbar = fig.colorbar(scat, ticks=[ticks[0], 0, ticks[1]])
            cbar.ax.set_yticklabels(["min", "0", "max"])

        def update(i, color, scat):
            scat.set_array(color[:, i])
            return (scat,)

        ani = animation.FuncAnimation(fig, update, frames=self.steps, fargs=(color, scat), blit=blit, repeat=False)
        return ani
Ejemplo n.º 33
0
    def get_animation_nb(self, s=300.0, fs=20.0, prop_type="real", figsize=None):
        """
        Get time evolution animation for iPython notebooks.

        :param s: Default value 300. Circle shape.
        :param fs: Default value 20. Fontsize.

        :returns:
           * **ani** -- Animation.
        """
        """
        Get time evolution animation.

        :param s: Default value 300. Circle size.
        :param fs: Default value 20. Fontsize.
        :param figsize: Tuple. Default value None. Figsize.
        :param prop_type: Default value None. Figsize.

        :returns:
          * **ani** -- Animation.
        """
        error_handling.empty_ndarray(self.prop, "get_propagation or get_pumping")
        error_handling.positive_real(s, "s")
        error_handling.positive_real(fs, "fs")
        error_handling.prop_type(prop_type)
        error_handling.tuple_2elem(figsize, "figsize")
        if prop_type == "real" or prop_type == "imag":
            color = self.prop.real
            max_val = max(np.max(color[:, -1]), -np.min(color[:, -1]))
            ticks = [-max_val, max_val]
            cmap = "seismic"
        else:
            color = np.abs(self.prop) ** 2
            ticks = [0.0, np.max(color)]
            cmap = "Reds"
        fig = plt.figure()
        ax = plt.axes(
            xlim=(np.min(self.lat.coor["x"] - 0.5), np.max(self.lat.coor["x"] + 0.5)),
            ylim=(np.min(self.lat.coor["y"] - 0.5), np.max(self.lat.coor["y"] + 0.5)),
        )
        ax.set_aspect("equal")
        frame = plt.gca()
        frame.axes.get_xaxis().set_ticks([])
        frame.axes.get_yaxis().set_ticks([])
        scat = plt.scatter(
            self.lat.coor["x"], self.lat.coor["y"], c=color[:, 0], s=s, vmin=ticks[0], vmax=ticks[1], cmap=cmap
        )
        if prop_type == "real" or prop_type == "imag":
            cbar = fig.colorbar(scat, ticks=[ticks[0], 0, ticks[1]])
            cbar.ax.set_yticklabels(["min", "0", "max"])
        else:
            cbar = fig.colorbar(scat, ticks=[0, ticks[1]])
            cbar.ax.set_yticklabels(["0", "max"])

        def init():
            scat.set_array(color[:, 0])
            return (scat,)

        def animate(i):
            scat.set_array(color[:, i])
            return (scat,)

        return animation.FuncAnimation(fig, animate, init_func=init, frames=self.steps, interval=120, blit=True)
Ejemplo n.º 34
0
    def intensity_area(self,
                       intensity,
                       s=1000.,
                       lw=1.,
                       fs=20.,
                       plt_hop=False,
                       figsize=None,
                       title=r'$|\psi|^2$'):
        '''
        Plot the intensity. Intensity propotional to disk shape.

        :param intensity: np.array. Intensity.
        :param s: Positive Float. Default value 1000. 
            Circle size given by s * intensity.
        :param lw: Positive Float. Default value 1. Hopping linewidths.
        :param fs: Positive Float. Default value 20. Fontsize.
        :param plt_hop: Boolean. Default value False. Plot hoppings.
        :param figsize: Tuple. Default value None. Figure size.
        :param title: String. Default value '$|\psi_{ij}|^2$'. Figure title.

        :returns:
            * **fig** -- Figure.
        '''
        error_handling.empty_ndarray(self.sys.lat.coor, 'sys.get_lattice')
        error_handling.ndarray(intensity, 'intensity', self.sys.lat.sites)
        error_handling.positive_real(s, 's')
        error_handling.positive_real(fs, 'fs')
        error_handling.boolean(plt_hop, 'plt_hop')
        error_handling.tuple_2elem(figsize, 'figsize')
        error_handling.string(title, 'title')
        fig, ax = plt.subplots()
        ax.set_xlabel('$i$', fontsize=fs)
        ax.set_ylabel('$j$', fontsize=fs)
        ax.set_title(title, fontsize=fs)
        if plt_hop:
            plt.plot([
                self.sys.lat.coor['x'][self.sys.hop['i'][:]],
                self.sys.lat.coor['x'][self.sys.hop['j'][:]]
            ], [
                self.sys.lat.coor['y'][self.sys.hop['i'][:]],
                self.sys.lat.coor['y'][self.sys.hop['j'][:]]
            ],
                     'k',
                     lw=lw)
        for tag, color in zip(self.sys.lat.tags, self.colors):
            plt.scatter(
                self.sys.lat.coor['x'][self.sys.lat.coor['tag'] == tag],
                self.sys.lat.coor['y'][self.sys.lat.coor['tag'] == tag],
                s=100 * s * intensity[self.sys.lat.coor['tag'] == tag],
                c=color,
                alpha=0.5)
        ax.set_aspect('equal')
        ax.axis('off')
        x_lim = [
            np.min(self.sys.lat.coor['x']) - 2.,
            np.max(self.sys.lat.coor['x']) + 2.
        ]
        y_lim = [
            np.min(self.sys.lat.coor['y']) - 2.,
            np.max(self.sys.lat.coor['y']) + 2.
        ]
        ax.set_xlim(x_lim)
        ax.set_ylim(y_lim)
        fig.set_tight_layout(True)
        plt.draw()
        return fig