Exemple #1
0
    def plot(self,
             npts: int = 0,
             xmin: float = None,
             xmax: float = None,
             width: float = None,
             smearing: str = 'Gauss',
             ax: 'matplotlib.axes.Axes' = None,
             show: bool = False,
             filename: str = None,
             mplargs: dict = None) -> 'matplotlib.axes.Axes':
        """Simple plot of collected DOS data, resampled onto a grid

        If the special key 'label' is present in self.info, this will be set
        as the label for the plotted line (unless overruled in mplargs). The
        label is only seen if a legend is added to the plot (i.e. by calling
        `ax.legend()`).

        Args:
            npts:
                Number of points in resampled x-axis. If set to zero (default),
                no resampling is performed and the stored data is plotted
                directly.
            xmin, xmax:
                output data range; this limits the resampling range as well as
                the plotting output
            width: Width of broadening kernel, passed to self.sample()
            smearing: selection of broadening kernel, passed to self.sample()
            ax: existing Matplotlib axes object. If not provided, a new figure
                with one set of axes will be created using Pyplot
            show: show the figure on-screen
            filename: if a path is given, save the figure to this file
            mplargs: additional arguments to pass to matplotlib plot command
                (e.g. {'linewidth': 2} for a thicker line).

        Returns:
            Plotting axes. If "ax" was set, this is the same object.
        """

        # Apply defaults if necessary
        npts, width = GridDOSData._interpret_smearing_args(npts, width)

        if npts:
            assert isinstance(width, float)
            dos = self.sample_grid(npts,
                                   xmin=xmin,
                                   xmax=xmax,
                                   width=width,
                                   smearing=smearing)
        else:
            dos = self

        energies, all_y = dos._energies, dos._weights

        all_labels = [DOSData.label_from_info(data.info) for data in self]

        with SimplePlottingAxes(ax=ax, show=show, filename=filename) as ax:
            self._plot_broadened(ax, energies, all_y, all_labels, mplargs)

        return ax
Exemple #2
0
 def test_smearing_args_interpreter(self, inputs, expected):
     assert GridDOSData._interpret_smearing_args(**inputs) == expected