def get_plot(self, zero_to_efermi=True, ylim=None, smooth=False,
                 vbm_cbm_marker=False, smooth_tol=None):
        """
        Get a matplotlib object for the bandstructure plot.
        Blue lines are up spin, red lines are down
        spin.

        Args:
            zero_to_efermi: Automatically subtract off the Fermi energy from
                the eigenvalues and plot (E-Ef).
            ylim: Specify the y-axis (energy) limits; by default None let
                the code choose. It is vbm-4 and cbm+4 if insulator
                efermi-10 and efermi+10 if metal
            smooth: interpolates the bands by a spline cubic
            smooth_tol (float) : tolerance for fitting spline to band data.
                Default is None such that no tolerance will be used.
        """
        plt = pretty_plot(12, 8)
        from matplotlib import rc
        import scipy.interpolate as scint

        # main internal config options
        e_min = -4
        e_max = 4
        if self._bs.is_metal():
            e_min = -10
            e_max = 10
        # band_linewidth = 3
        band_linewidth = 1

        data = self.bs_plot_data(zero_to_efermi)
        if not smooth:
            for d in range(len(data['distances'])):
                for i in range(self._nb_bands):
                    plt.plot(data['distances'][d],
                             [data['energy'][d][str(Spin.up)][i][j]
                              for j in range(len(data['distances'][d]))], 'b-',
                             linewidth=band_linewidth)
                    if self._bs.is_spin_polarized:
                        plt.plot(data['distances'][d],
                                 [data['energy'][d][str(Spin.down)][i][j]
                                  for j in range(len(data['distances'][d]))],
                                 'r--', linewidth=band_linewidth)
        else:
            # Interpolation failure can be caused by trying to fit an entire
            # band with one spline rather than fitting with piecewise splines
            # (splines are ill-suited to fit discontinuities).
            #
            # The number of splines used to fit a band is determined by the 
            # number of branches (high symmetry lines) defined in the 
            # BandStructureSymmLine object (see BandStructureSymmLine._branches). 

            warning = "WARNING! Distance / branch {d}, band {i} cannot be " + \
                      "interpolated.\n" + \
                      "See full warning in source.\n" + \
                      "If this is not a mistake, try increasing " + \
                      "smooth_tol.\nCurrent smooth_tol is {s}."

            for d in range(len(data['distances'])):
                for i in range(self._nb_bands):
                    tck = scint.splrep(
                        data['distances'][d],
                        [data['energy'][d][str(Spin.up)][i][j]
                         for j in range(len(data['distances'][d]))],
                        s=smooth_tol)
                    step = (data['distances'][d][-1]
                            - data['distances'][d][0]) / 1000

                    xs = [x * step + data['distances'][d][0]
                          for x in range(1000)]

                    ys = [scint.splev(x * step + data['distances'][d][0],
                                      tck, der=0)
                          for x in range(1000)]

                    for y in ys:
                        if np.isnan(y):
                            print(warning.format(d=str(d), i=str(i),
                                                 s=str(smooth_tol)))
                            break

                    plt.plot(xs, ys, 'b-', linewidth=band_linewidth)

                    if self._bs.is_spin_polarized:
                        tck = scint.splrep(
                            data['distances'][d],
                            [data['energy'][d][str(Spin.down)][i][j]
                             for j in range(len(data['distances'][d]))],
                            s=smooth_tol)
                        step = (data['distances'][d][-1]
                                - data['distances'][d][0]) / 1000

                        xs = [x * step + data['distances'][d][0]
                              for x in range(1000)]

                        ys = [scint.splev(
                            x * step + data['distances'][d][0],
                            tck, der=0)
                            for x in range(1000)]

                        for y in ys:
                            if np.isnan(y):
                                print(warning.format(d=str(d), i=str(i),
                                                     s=str(smooth_tol)))
                                break

                        plt.plot(xs, ys, 'r--', linewidth=band_linewidth)

        self._maketicks(plt)

        # Main X and Y Labels
        plt.xlabel(r'$\mathrm{Wave\ Vector}$', fontsize=30)
        ylabel = r'$\mathrm{E\ -\ E_f\ (eV)}$' if zero_to_efermi \
            else r'$\mathrm{Energy\ (eV)}$'
        plt.ylabel(ylabel, fontsize=30)

        # Draw Fermi energy, only if not the zero
        if not zero_to_efermi:
            ef = self._bs.efermi
            plt.axhline(ef, linewidth=2, color='k')

        # X range (K)
        # last distance point
        x_max = data['distances'][-1][-1]
        plt.xlim(0, x_max)

        if ylim is None:
            if self._bs.is_metal():
                # Plot A Metal
                if zero_to_efermi:
                    plt.ylim(e_min, e_max)
                else:
                    plt.ylim(self._bs.efermi + e_min, self._bs.efermi + e_max)
            else:
                if vbm_cbm_marker:
                    for cbm in data['cbm']:
                        plt.scatter(cbm[0], cbm[1], color='r', marker='o',
                                    s=100)
                    for vbm in data['vbm']:
                        plt.scatter(vbm[0], vbm[1], color='g', marker='o',
                                    s=100)
                plt.ylim(data['vbm'][0][1] + e_min,
                         data['cbm'][0][1] + e_max)
        else:
            plt.ylim(ylim)
            if not self._bs.is_metal() and vbm_cbm_marker:
                for cbm in data['cbm']:
                        plt.scatter(cbm[0], cbm[1], color='r', marker='o',
                                    s=100)
                for vbm in data['vbm']:
                        plt.scatter(vbm[0], vbm[1], color='g', marker='o',
                                    s=100)

        plt.tight_layout()

        return plt
def get_plot ( self , zero_to_efermi = True , ylim = None , smooth = False , vbm_cbm_marker = False , smooth_tol = None ) : plt = pretty_plot ( 12 , 8 ) from matplotlib import rc import scipy . interpolate as scint e_min = - 4 e_max = 4 if self . _bs . is_metal ( ) : e_min = - 10 e_max = 10 band_linewidth = 1 data = self . bs_plot_data ( zero_to_efermi ) if not smooth : for d in range ( len ( data [ 'distances' ] ) ) : for i in range ( self . _nb_bands ) : plt . plot ( data [ 'distances' ] [ d ] , [ data [ 'energy' ] [ d ] [ str ( Spin . up ) ] [ i ] [ j ] for j in range ( len ( data [ 'distances' ] [ d ] ) ) ] , 'b-' , linewidth = band_linewidth ) if self . _bs . is_spin_polarized : plt . plot ( data [ 'distances' ] [ d ] , [ data [ 'energy' ] [ d ] [ str ( Spin . down ) ] [ i ] [ j ] for j in range ( len ( data [ 'distances' ] [ d ] ) ) ] , 'r--' , linewidth = band_linewidth ) else : warning = "WARNING! Distance / branch {d}, band {i} cannot be " + "interpolated.\n" + "See full warning in source.\n" + "If this is not a mistake, try increasing " + "smooth_tol.\nCurrent smooth_tol is {s}." for d in range ( len ( data [ 'distances' ] ) ) : for i in range ( self . _nb_bands ) : tck = scint . splrep ( data [ 'distances' ] [ d ] , [ data [ 'energy' ] [ d ] [ str ( Spin . up ) ] [ i ] [ j ] for j in range ( len ( data [ 'distances' ] [ d ] ) ) ] , s = smooth_tol ) step = ( data [ 'distances' ] [ d ] [ - 1 ] - data [ 'distances' ] [ d ] [ 0 ] ) / 1000 xs = [ x * step + data [ 'distances' ] [ d ] [ 0 ] for x in range ( 1000 ) ] ys = [ scint . splev ( x * step + data [ 'distances' ] [ d ] [ 0 ] , tck , der = 0 ) for x in range ( 1000 ) ] for y in ys : if np . isnan ( y ) : print ( warning . format ( d = str ( d ) , i = str ( i ) , s = str ( smooth_tol ) ) ) break plt . plot ( xs , ys , 'b-' , linewidth = band_linewidth ) if self . _bs . is_spin_polarized : tck = scint . splrep ( data [ 'distances' ] [ d ] , [ data [ 'energy' ] [ d ] [ str ( Spin . down ) ] [ i ] [ j ] for j in range ( len ( data [ 'distances' ] [ d ] ) ) ] , s = smooth_tol ) step = ( data [ 'distances' ] [ d ] [ - 1 ] - data [ 'distances' ] [ d ] [ 0 ] ) / 1000 xs = [ x * step + data [ 'distances' ] [ d ] [ 0 ] for x in range ( 1000 ) ] ys = [ scint . splev ( x * step + data [ 'distances' ] [ d ] [ 0 ] , tck , der = 0 ) for x in range ( 1000 ) ] for y in ys : if np . isnan ( y ) : print ( warning . format ( d = str ( d ) , i = str ( i ) , s = str ( smooth_tol ) ) ) break plt . plot ( xs , ys , 'r--' , linewidth = band_linewidth ) self . _maketicks ( plt ) plt . xlabel ( r'$\mathrm{Wave\ Vector}$' , fontsize = 30 ) ylabel = r'$\mathrm{E\ -\ E_f\ (eV)}$' if zero_to_efermi else r'$\mathrm{Energy\ (eV)}$' plt . ylabel ( ylabel , fontsize = 30 ) if not zero_to_efermi : ef = self . _bs . efermi plt . axhline ( ef , linewidth = 2 , color = 'k' ) x_max = data [ 'distances' ] [ - 1 ] [ - 1 ] plt . xlim ( 0 , x_max ) if ylim is None : if self . _bs . is_metal ( ) : if zero_to_efermi : plt . ylim ( e_min , e_max ) else : plt . ylim ( self . _bs . efermi + e_min , self . _bs . efermi + e_max ) else : if vbm_cbm_marker : for cbm in data [ 'cbm' ] : plt . scatter ( cbm [ 0 ] , cbm [ 1 ] , color = 'r' , marker = 'o' , s = 100 ) for vbm in data [ 'vbm' ] : plt . scatter ( vbm [ 0 ] , vbm [ 1 ] , color = 'g' , marker = 'o' , s = 100 ) plt . ylim ( data [ 'vbm' ] [ 0 ] [ 1 ] + e_min , data [ 'cbm' ] [ 0 ] [ 1 ] + e_max ) else : plt . ylim ( ylim ) if not self . _bs . is_metal ( ) and vbm_cbm_marker : for cbm in data [ 'cbm' ] : plt . scatter ( cbm [ 0 ] , cbm [ 1 ] , color = 'r' , marker = 'o' , s = 100 ) for vbm in data [ 'vbm' ] : plt . scatter ( vbm [ 0 ] , vbm [ 1 ] , color = 'g' , marker = 'o' , s = 100 ) plt . tight_layout ( ) return plt
Get a matplotlib object for the bandstructure plot.
        Blue lines are up spin, red lines are down
        spin.

        Args:
            zero_to_efermi: Automatically subtract off the Fermi energy from
                the eigenvalues and plot (E-Ef).
            ylim: Specify the y-axis (energy) limits; by default None let
                the code choose. It is vbm-4 and cbm+4 if insulator
                efermi-10 and efermi+10 if metal
            smooth: interpolates the bands by a spline cubic
            smooth_tol (float) : tolerance for fitting spline to band data.
                Default is None such that no tolerance will be used.