Exemple #1
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)
Exemple #2
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)
Exemple #3
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
Exemple #4
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
Exemple #5
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)
Exemple #6
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)
Exemple #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
Exemple #8
0
    def find_square(self, xlims, ylims):
        '''
        Private method.
        Find hoppings within the square.

        :param xlims: List or Tuple. :math:`x` interval.
        :param ylims: List or Tuple. :math:`y` interval.
        '''
        error_handling.lims(xlims)
        error_handling.lims(ylims)
        in1 = (self.lat.coor['x'][self.hop['i']] >= xlims[0]) & \
                 (self.lat.coor['y'][self.hop['i']] >= ylims[0]) & \
                 (self.lat.coor['x'][self.hop['j']] >= xlims[0]) & \
                 (self.lat.coor['y'][self.hop['j']] >= ylims[0])
        in2 = (self.lat.coor['x'][self.hop['i']] <= xlims[1]) & \
                 (self.lat.coor['y'][self.hop['i']] <= ylims[1]) & \
                 (self.lat.coor['x'][self.hop['j']] <= xlims[1]) & \
                 (self.lat.coor['y'][self.hop['j']] <= ylims[1])
        return in1 * in2
Exemple #9
0
    def find_square(self, xlims, ylims):
        '''
        Private method.
        Find hoppings within the square.

        :param xlims: List or Tuple. :math:`x` interval.
        :param ylims: List or Tuple. :math:`y` interval.
        '''
        error_handling.lims(xlims)
        error_handling.lims(ylims)
        in1 = (self.lat.coor['x'][self.hop['i']] >= xlims[0]) & \
                 (self.lat.coor['y'][self.hop['i']] >= ylims[0]) & \
                 (self.lat.coor['x'][self.hop['j']] >= xlims[0]) & \
                 (self.lat.coor['y'][self.hop['j']] >= ylims[0])
        in2 = (self.lat.coor['x'][self.hop['i']] <= xlims[1]) & \
                 (self.lat.coor['y'][self.hop['i']] <= ylims[1]) & \
                 (self.lat.coor['x'][self.hop['j']] <= xlims[1]) & \
                 (self.lat.coor['y'][self.hop['j']] <= ylims[1])
        return in1 * in2
Exemple #10
0
    def butterfly(self, betas, butterfly, lw=1., fs=20., lims=None, title=''):
        '''
        Plot energies depending on a parameter.

        :param betas: np.array. Parameter values.
        :param butterfly: np.array. Eigenvalues.
        :param lw: Positive Float. Default value 1. Hopping linewidths.
        :param fs: Positive Float. Default value 20. Fontsize.
        :param lims: List, lims[0] energy min, lims[1] energy max.
        :param title: Default value ''. Figure title.
        '''
        error_handling.ndarray_empty(betas, 'betas')
        error_handling.ndarray_empty(butterfly, 'butterfly')
        error_handling.positive_real(lw, 'lw')
        error_handling.positive_real(fs, 'fs')
        error_handling.lims(lims)
        error_handling.string(title, 'title')
        i_beta_min = np.argmin(np.abs(betas))
        if lims is None:
            lims = [butterfly[i_beta_min, 0], butterfly[i_beta_min, -1]]
        ind_en = np.argwhere((butterfly[i_beta_min, :] > lims[0])
                             & (butterfly[i_beta_min, :] < lims[1]))
        ind_en = np.ravel(ind_en)
        fig, ax = plt.subplots()
        plt.title('Energies depending on strain', fontsize=fs)
        plt.xlabel(r'$\beta/\beta_{max}$', fontsize=fs)
        plt.ylabel('$E$', fontsize=fs)
        ax.set_title(title, fontsize=fs)
        plt.yticks(np.arange(lims[0], lims[1] + 1, (lims[1] - lims[0]) / 4),
                   fontsize=fs)
        plt.ylim(lims)
        beta_max = max(self.sys.betas)
        plt.xticks([-beta_max, -0.5 * beta_max, 0, 0.5 * beta_max, beta_max],
                   fontsize=fs)
        ax.set_xticklabels(('-1', '-1/2', '0', '1/2', '1'))
        plt.xlim([betas[0], betas[-1]])
        for i in ind_en:
            plt.plot(betas, butterfly[:, i], 'b', lw=lw)
        fig.set_tight_layout(True)
        plt.draw()
        return fig
Exemple #11
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
Exemple #12
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
Exemple #13
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
Exemple #14
0
    def butterfly(self, betas, butterfly, lw=1., fs=20., lims=None, title=''):
        '''
        Plot energies depending on a parameter.

        :param betas: np.array. Parameter values.
        :param butterfly: np.array. Eigenvalues.
        :param lw: Positive Float. Default value 1. Hopping linewidths.
        :param fs: Positive Float. Default value 20. Fontsize.
        :param lims: List, lims[0] energy min, lims[1] energy max.
        :param title: Default value ''. Figure title.
        '''
        error_handling.ndarray_empty(betas, 'betas')
        error_handling.ndarray_empty(butterfly, 'butterfly')
        error_handling.positive_real(lw, 'lw')
        error_handling.positive_real(fs, 'fs')
        error_handling.lims(lims)
        error_handling.string(title, 'title')
        i_beta_min = np.argmin(np.abs(betas))
        if lims is None:
            lims = [butterfly[i_beta_min, 0], butterfly[i_beta_min, -1]]
        ind_en = np.argwhere((butterfly[i_beta_min, :] > lims[0]) & 
                                            (butterfly[i_beta_min, :] < lims[1]))
        ind_en = np.ravel(ind_en)
        fig, ax = plt.subplots()
        plt.title('Energies depending on strain', fontsize=fs)
        plt.xlabel(r'$\beta/\beta_{max}$', fontsize=fs)
        plt.ylabel('$E$', fontsize=fs)
        ax.set_title(title, fontsize=fs)
        plt.yticks(np.arange(lims[0], lims[1]+1, (lims[1]-lims[0])/4), fontsize=fs)
        plt.ylim(lims)
        beta_max = max(self.sys.betas)
        plt.xticks([-beta_max, -0.5*beta_max, 0, 
                        0.5*beta_max, beta_max], fontsize=fs)
        ax.set_xticklabels(('-1', '-1/2', '0', '1/2', '1'))
        plt.xlim([betas[0], betas[-1]])
        for i in ind_en:
            plt.plot(betas, butterfly[:, i], 'b', lw=lw)
        fig.set_tight_layout(True)
        plt.draw()
        return fig
Exemple #15
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
Exemple #16
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