def plot_gg(self, cplx_mode="abs", wpos=None, **kwargs): r""" Use matplotlib imshow to plot :math:`W_{GG'}` matrix Args: cplx_mode: string defining the data to print. Possible choices are (case-insensitive): ``re`` for the real part ``im`` for the imaginary part, ``abs`` for the absolute value. ``angle`` will display the phase of the complex number in radians. wpos: List of frequency indices to plot. If None, the first frequency is used (usually w=0). If wpos == "all" all frequencies are shown (use it carefully) Other possible values: "real" if only real frequencies are wanted. "imag" for imaginary frequencies only. Returns: |matplotlib-Figure| """ # Get wpos indices. choice_wpos = {None: [0], "all": range(self.nw), "real": range(self.nrew), "imag": range(self.nrew, self.nw)} if any(wpos == k for k in choice_wpos): wpos = choice_wpos[wpos] else: if duck.is_intlike(wpos): wpos = [int(wpos)] wpos = np.array(wpos) # Build plotter. plotter = ArrayPlotter() for iw in wpos: label = r"%s $\omega=%s$" % (self.latex_label(cplx_mode), self.wpoints[iw]) data = data_from_cplx_mode(cplx_mode, self.wggmat[iw]) plotter.add_array(label, data) return plotter.plot(show=False, **kwargs)
def plot_emacro(self, cplx_mode="re-im", ax=None, xlims=None, fontsize=12, **kwargs): r""" Plot the macroscopic dielectric function with local-field effects. Args: cplx_mode: string defining the data to print. Possible choices are (case-insensitive): "re" for the real part. "im" for the imaginary part. "abs" for the absolute value. "angle" will display the phase of the complex number in radians. Options can be concatenated with ``-`` e.g. ``re-im``. xlims: Set the data limits for the x-axis in eV. Accept tuple e.g. (left, right) or scalar e.g. left. If left (right) is None, default values are used. ax: |matplotlib-Axes| or None if a new figure should be created. fontsize: Legend and title fontsize. Returns: |matplotlib-Figure| """ emlf = self.reader.read_emacro_lf() xx, yy = emlf.mesh * pmgu.Ha_to_eV, emlf.values ax, fig, plt = get_ax_fig_plt(ax=ax) for c in cplx_mode.lower().split("-"): ax.plot(xx, data_from_cplx_mode(c, yy), color=_COLOR_CMODE[c], linewidth=kwargs.get("linewidth", 2), linestyle=kwargs.get("linestyle", "solid"), label=_latex_symbol_cplxmode(r"\varepsilon_{M}", c)) set_axlims(ax, xlims, "x") ax.grid(True) ax.set_xlabel(r"$\omega$ (eV)") ax.legend(loc="best", shadow=True, fontsize=fontsize) return fig
def plot_chi2(self, key, components="all", what="abs", itemp=0, decompose=False, ax=None, xlims=None, with_xlabel=True, label=None, fontsize=12, **kwargs): """ Low-level function to plot chi2 tensor. Args: key: components: List of cartesian tensor components to plot e.g. ["xxx", "xyz"]. "all" if all components available on file should be plotted on the same ax. what: quantity to plot. "re" for real part, "im" for imaginary, Accepts also "abs", "angle". itemp: Temperature index. decompose: True to plot individual contributions. ax: |matplotlib-Axes| or None if a new figure should be created. xlims: Set the data limits for the x-axis. Accept tuple e.g. ``(left, right)`` or scalar e.g. ``left``. If left (right) is None, default values are used. with_xlabel: True to add x-label. label: True to add legend label to each curve. fontsize: Legend and label fontsize. Returns: |matplotlib-Figure| """ if not self.reader.computed_components[key]: return None comp2terms = self.reader.read_tensor3_terms(key, components, itemp=itemp) ax, fig, plt = get_ax_fig_plt(ax=ax) for comp, terms in comp2terms.items(): for name, values in terms.items(): if not decompose and not name.endswith("tot"): continue values = data_from_cplx_mode(what, values) ax.plot( self.wmesh[1:], values[1:], label=self.get_chi2_latex_label(key, what, comp) if label is None else label, ) ax.grid(True) if with_xlabel: ax.set_xlabel('Photon Energy [eV]') set_axlims(ax, xlims, "x") ax.legend(loc="best", fontsize=fontsize, shadow=True) return fig
def plot_freq(self, gvec1, gvec2=None, waxis="real", cplx_mode="re-im", ax=None, fontsize=12, **kwargs): r""" Plot the frequency dependence of :math:`W_{G1, G2}(\omega)` Args: gvec1, gvec2: waxis: ``real`` to plot along the real axis, ``imag`` for the imaginary axis. cplx_mode: string defining the data to print. Possible choices are (case-insensitive): ``re`` for the real part ``im`` for the imaginary part, ``abs`` for the absolute value. ``angle`` will display the phase of the complex number in radians. Options can be concatenated with ``-`` e.g. ``re-im``. ax: |matplotlib-Axes| or None if a new figure should be created. fontsize: legend and label fontsize. Returns: |matplotlib-Figure| """ # Select data to plot ig1 = self.gindex(gvec1) ig2 = ig1 if gvec2 is None else self.gindex(gvec2) ax, fig, plt = get_ax_fig_plt(ax=ax) if waxis == "real": if self.nrew == 0: return fig xx = self.real_wpoints.real * pmgu.Ha_to_eV yy = self.wggmat_realw[:, ig1, ig2] elif waxis == "imag": if self.nimw == 0: return fig xx = self.imag_wpoints.imag * pmgu.Ha_to_eV yy = self.wggmat_imagw[:, ig1, ig2] else: raise ValueError("Wrong value for waxis: %s" % str(waxis)) linewidth = kwargs.pop("linewidth", 2) linestyle = kwargs.pop("linestyle", "solid") lines = [] for c in cplx_mode.lower().split("-"): l, = ax.plot(xx, data_from_cplx_mode(c, yy), color=_COLOR_CMODE[c], linewidth=linewidth, linestyle=linestyle, label=self.latex_label(c)) lines.append(l) ax.grid(True) ax.set_xlabel(r"$\omega$ (eV)") ax.set_title("%s, kpoint: %s" % (self.netcdf_name, self.kpoint), fontsize=fontsize) ax.legend(loc="best", fontsize=fontsize, shadow=True) return fig
def plot_ax(self, ax, exchange_xy=False, xfactor=1, yfactor=1, *args, **kwargs): """ Helper function to plot self on axis ax. Args: ax: |matplotlib-Axes|. exchange_xy: True to exchange the axis in the plot. args: Positional arguments passed to ax.plot xfactor, yfactor: xvalues and yvalues are multiplied by this factor before plotting. kwargs: Keyword arguments passed to ``matplotlib``. Accepts ============== =============================================================== kwargs Meaning ============== =============================================================== cplx_mode string defining the data to print. Possible choices are (case-insensitive): `re` for the real part "im" for the imaginary part, "abs" for the absolute value. "angle" to display the phase of the complex number in radians. Options can be concatenated with "-" ============== =============================================================== Returns: List of lines added. """ if self.iscomplexobj: cplx_mode = kwargs.pop("cplx_mode", "re-im") else: cplx_mode = kwargs.pop("cplx_mode", "re") lines = [] for c in cplx_mode.lower().split("-"): xx, yy = self.mesh, data_from_cplx_mode(c, self.values) if xfactor != 1: xx = xx * xfactor if yfactor != 1: yy = yy * yfactor if exchange_xy: xx, yy = yy, xx lines.extend(ax.plot(xx, yy, *args, **kwargs)) return lines
def plot_chi2(self, key, components="all", what="abs", itemp=0, decompose=False, ax=None, xlims=None, with_xlabel=True, label=None, fontsize=12, **kwargs): """ Low-level function to plot chi2 tensor. Args: key: components: List of cartesian tensor components to plot e.g. ["xxx", "xyz"]. "all" if all components available on file should be plotted on the same ax. what: quantity to plot. "re" for real part, "im" for imaginary, Accepts also "abs", "angle". itemp: Temperature index. decompose: True to plot individual contributions. ax: |matplotlib-Axes| or None if a new figure should be created. xlims: Set the data limits for the x-axis. Accept tuple e.g. ``(left, right)`` or scalar e.g. ``left``. If left (right) is None, default values are used. with_xlabel: True to add x-label. label: True to add legend label to each curve. fontsize: Legend and label fontsize. Returns: |matplotlib-Figure| """ if not self.reader.computed_components[key]: return None comp2terms = self.reader.read_tensor3_terms(key, components, itemp=itemp) ax, fig, plt = get_ax_fig_plt(ax=ax) for comp, terms in comp2terms.items(): for name, values in terms.items(): if not decompose and not name.endswith("tot"): continue values = data_from_cplx_mode(what, values) ax.plot(self.wmesh[1:], values[1:], label=self.get_chi2_latex_label(key, what, comp) if label is None else label, ) ax.grid(True) if with_xlabel: ax.set_xlabel('Photon Energy (eV)') set_axlims(ax, xlims, "x") ax.legend(loc="best", fontsize=fontsize, shadow=True) return fig
def plot_ggmat(self, cplx_mode="abs", wpos=None, **kwargs): """ Use imshow for plotting W_GG'. Args: cplx_mode: wpos: List of frequency indices to plot. If None, the first frequency is used (usually w=0). if wpos == "all" all frequencies are shown (use it carefully) Other possible values: "real" if only real frequencies are wanted. "imag" for imaginary frequencies only. Returns: `matplotlib` figure. """ # Get wpos indices. choice_wpos = { None: [0], "all": range(self.nw), "real": range(self.nrew), "imag": range(self.nrew, self.nw) } if any(wpos == k for k in choice_wpos): wpos = choice_wpos[wpos] else: if isinstance(wpos, int): wpos = [wpos] wpos = np.array(wpos) # Build plotter. plotter = ArrayPlotter() for iw in wpos: label = cplx_mode + r" $\omega = %s" % self.wpts[iw] data = data_from_cplx_mode(cplx_mode, self.wggmat[iw, :, :]) plotter.add_array(label, data) return plotter.plot(**kwargs)
def plot_w(self, gvec1, gvec2=None, waxis="real", cplx_mode="re-im", ax=None, **kwargs): """ Plot the frequency dependence of W_{g1, g2} Args: gvec1, gvec2: waxis: "real" to plot along the real axis, "imag" for the imaginary axis. cplx_mode: string defining the data to print. Possible choices are (case-insensitive): `re` for the real part "im" for the imaginary part, "abs" for the absolute value. "angle" will display the phase of the complex number in radians. Options can be concatenated with "-" e.g. "re-im" ax: matplotlib :class:`Axes` or None if a new figure should be created. Returns: matplotlib figure. """ # Select data to plot ig1 = self.gindex(gvec1) ig2 = ig1 if gvec2 is None else self.gindex(gvec2) ax, fig, plt = get_ax_fig_plt(ax) if waxis == "real": if self.nrew == 0: return fig xx = (self.real_wpts * Ha_to_eV).real yy = self.wggmat_realw[:, ig1, ig2] elif waxis == "imag": if self.nimw == 0: return fig xx = (self.imag_wpts * Ha_to_eV).imag yy = self.wggmat_imagw[:, ig1, ig2] else: raise ValueError("Wrong value for waxis: %s" % waxis) color_cmode = dict(re="red", im="blue", abs="black", angle="green") linewidth = kwargs.pop("linewidth", 2) linestyle = kwargs.pop("linestyle", "solid") lines = [] for c in cplx_mode.lower().split("-"): l, = ax.plot(xx, data_from_cplx_mode(c, yy), color=color_cmode[c], linewidth=linewidth, linestyle=linestyle, label=self.latex_label(c)) lines.append(l) ax.grid(True) ax.set_xlabel(r"$\omega$ [eV]") ax.set_title("%s, qpoint: %s" % (self.etsf_name, self.qpoint)) #ax.legend(loc="best") ax.legend(loc="upper right") return fig