elisa.plot.plotter#

Visualize fit and analysis results.

class PlotConfig(alpha: float = 0.8, palette: Any = 'colorblind', xscale: Literal['linear', 'log'] = 'log', yscale: Literal['linear', 'log', 'linlog'] = 'linlog', lin_frac: float = 0.15, cl: tuple[float, ...] = (0.683, 0.95), residuals: Literal['rd', 'rp', 'rq'] = 'rq', random_quantile: bool = False, mark_outlier_residuals: bool = False, residuals_ci_with_sign: bool = True, fill_residuals_ci: bool = True, plot_comps: bool = False, seed: int | None = None)[source]#

Bases: object

Plotting configuration.

Attributes

alpha

Transparency of colors.

cl

Confidence/Credible level.

fill_residuals_ci

Whether to fill residuals' CI bands.

lin_frac

Linear fraction of the linlog plot.

mark_outlier_residuals

Whether to mark outlier residuals with red crosses.

palette

Color palettes, see [1] for details.

plot_comps

Whether to plot additive components in spectral plot.

random_quantile

Whether to randomize the quantile residual.

residuals

Default type of residual plot.

residuals_ci_with_sign

Whether to take account residuals' sign when calculate CI bands.

seed

Random seed used in calculation.

xscale

X-axis scale of spectral plot.

yscale

X-axis scale of spectral plot.

property alpha: float#

Transparency of colors.

property palette: Any#

Color palettes, see [1] for details.

References

property xscale: Literal['linear', 'log']#

X-axis scale of spectral plot.

Should be 'linear', or 'log'.

property yscale: Literal['linear', 'log', 'linlog']#

X-axis scale of spectral plot.

Should be 'linear', 'log', or 'linlog'.

property lin_frac: float#

Linear fraction of the linlog plot.

property cl: ndarray#

Confidence/Credible level.

property residuals: Literal['rd', 'rp', 'rq']#

Default type of residual plot.

property random_quantile: bool#

Whether to randomize the quantile residual.

property mark_outlier_residuals: bool#

Whether to mark outlier residuals with red crosses.

property residuals_ci_with_sign: bool#

Whether to take account residuals’ sign when calculate CI bands.

property fill_residuals_ci: bool#

Whether to fill residuals’ CI bands.

property plot_comps: bool#

Whether to plot additive components in spectral plot.

property seed: int | None#

Random seed used in calculation.

class Plotter(result: FitResult, config: PlotConfig = None)[source]#

Bases: ABC

Plotter to visualize fit results.

Attributes

colors

Plotting color for each data.

comps_latex

LaTeX representation of components.

config

Plotting configuration.

ndata

Data points number.

params_labels

Label of parameters.

params_latex

LaTeX representation of parameters.

params_titles

Title of parameters.

params_unit

Unit of parameters.

data

Methods

__call__([plots])

Call self as a function.

get_plot_data(result)

Get PlotData from FitResult.

plot_ce(ax)

Plot data.

plot_corner(*args, **kwargs)

Corner plot of bootstrap/posterior parameters.

plot_folded(ax)

Plot folded model.

plot_gof()

Plot distribution of GOF statistics and p-value.

plot_pit([detrend])

Probability integral transformation empirical CDF plot.

plot_qq([rtype, seed, detrend])

Quantile-Quantile plot.

plot_residuals(ax[, rtype])

Plot residuals.

plot_spec([data, ne, ene, eene, residuals, ...])

Spectral plot.

plot_unfolded(ax, mtype[, params, egrid, ...])

Plot unfolded model.

set_colors([colors])

Specify the colors of data points used in the plots.

set_xlabel

data: dict[str, PlotData] | None = None#
abstractmethod plot_corner(*args, **kwargs) Figure[source]#

Corner plot of bootstrap/posterior parameters.

abstractmethod static get_plot_data(result: FitResult) dict[str, PlotData][source]#

Get PlotData from FitResult.

property config: PlotConfig#

Plotting configuration.

set_colors(colors: dict[str, Any] | None = None)[source]#

Specify the colors of data points used in the plots.

Parameters:
colorsdict or None, optional

If a dict is provided, will use the provided values as colors. If None, the default colors will be used. The default is None.

property colors#

Plotting color for each data.

property ndata#

Data points number.

property comps_latex: dict[str, str]#

LaTeX representation of components.

property params_latex: dict[str, str]#

LaTeX representation of parameters.

property params_unit: dict[str, str]#

Unit of parameters.

property params_titles: dict[str, str]#

Title of parameters.

property params_labels: dict[str, str]#

Label of parameters.

set_xlabel(ax: Axes)[source]#
plot_spec(data: bool = True, ne: bool = True, ene: bool = False, eene: bool = False, residuals: bool | Literal['rd', 'rp', 'rq'] = True, *, egrid: Mapping[str, ndarray] | None = None, params: Mapping[str, float | int | ndarray | Array] | None = None, label_Fv: bool = False, label_vFv: bool = False, label_FvJy: bool = False) Figure[source]#

Spectral plot.

Parameters:
databool, optional

Whether to plot folded model and data. The default is True.

nebool, optional

Whether to plot \(N(E)\). The default is True.

enebool, optional

Whether to plot \(E N(E)\). The default is False.

eenebool, optional

Whether to plot \(E^2 N(E)\). The default is False.

residualsbool or {‘rd’, ‘rp’, ‘rq’}, optional

Whether to plot residuals. Available options are:

  • True: plot default residuals

  • False: do not plot residuals

  • 'rd': plot deviance residuals

  • 'rp': plot Pearson residuals

  • 'rq': plot quantile residuals

The default is True.

egriddict, optional

Overwrite the photon energy grid when plotting unfolded model.

paramsdict, optional

Overwrite the photon energy grid when plotting unfolded model.

label_Fvbool, optional

Whether to label the y-axis of \(E N(E)\) plot as \(F_{\nu}\). The default is False.

label_vFvbool, optional

Whether to label the y-axis of \(E^2 N(E)\) plot as \(\nu F_{\nu}\). The default is False.

label_FvJybool, optional

Whether to label the y-axis of \(E N(E)\) plot as \(F_{\nu}\) in Jy and convert values to Jy. The default is False.

Returns:
Figure

The Figure object containing the spectral plot.

plot_unfolded(ax: Axes, mtype: Literal['ne', 'ene', 'eene'], params: Mapping[str, float | int | ndarray | Array] | None = None, egrid: Mapping[str, ndarray] | None = None, label_Fv: bool = False, label_vFv: bool = False, label_FvJy: bool = False)[source]#

Plot unfolded model.

Parameters:
axAxes

The Axes object to plot.

mtype{‘ne’, ‘ene’, ‘eene’}

The type of unfolded model, available options are:

  • 'ne': plot \(N(E)\)

  • 'ene': plot \(E N(E)\)

  • 'eene': plot \(E^2 N(E)\)

paramsdict, optional

Overwrite the parameters when plotting unfolded model.

egriddict, optional

Overwrite the photon energy grid when plotting unfolded model.

label_Fvbool, optional

Whether to label the y-axis of \(E N(E)\) plot as \(F_{\nu}\). The default is False.

label_vFvbool, optional

Whether to label the y-axis of \(E^2 N(E)\) plot as \(\nu F_{\nu}\). The default is False.

label_FvJybool, optional

Whether to label the y-axis of \(E N(E)\) plot as \(F_{\nu}\) in Jy and convert values to Jy. The default is False.

plot_folded(ax: Axes)[source]#

Plot folded model.

Parameters:
axAxes

The Axes object to plot.

plot_ce(ax: Axes)[source]#

Plot data.

Parameters:
axAxes

The Axes object to plot.

plot_residuals(ax: Axes, rtype: Literal['rd', 'rp', 'rq'] | None = None)[source]#

Plot residuals.

Parameters:
axAxes

The Axes object to plot.

rtype{‘rd’, ‘rp’, ‘rq’}, optional

The type of residuals, available options are:

  • 'rd': deviance residuals

  • 'rp': Pearson residuals

  • 'rq': quantile residuals

plot_qq(rtype: Literal['rd', 'rp', 'rq'] | None = None, seed: int | None = None, detrend: bool = True) Figure[source]#

Quantile-Quantile plot.

Parameters:
rtype{‘rd’, ‘rp’, ‘rq’}, optional

The type of residuals, available options are:

  • 'rd': deviance residuals

  • 'rp': Pearson residuals

  • 'rq': quantile residuals

  • None: use the default residuals type

The default is None.

seedint, optional

Random seed used in calculation. The default is None.

detrendbool, optional

Whether to detrend the Q-Q plot. The default is True.

Returns:
Figure

The Figure object containing Q-Q plot.

plot_pit(detrend=True) Figure[source]#

Probability integral transformation empirical CDF plot.

Parameters:
detrendbool, optional

Whether to detrend the PIT ECDF plot. The default is True.

Returns:
Figure

The Figure object containing PIT ECDF plot.

plot_gof() Figure[source]#

Plot distribution of GOF statistics and p-value.

Returns:
Figure

The Figure object containing GOF statistics plot.

class MLEResultPlotter(result: FitResult, config: PlotConfig = None)[source]#

Bases: Plotter

Attributes

colors

Plotting color for each data.

comps_latex

LaTeX representation of components.

config

Plotting configuration.

ndata

Data points number.

params_labels

Label of parameters.

params_latex

LaTeX representation of parameters.

params_titles

Title of parameters.

params_unit

Unit of parameters.

data

Methods

__call__([plots])

Plot MLE fit results.

get_plot_data(result)

Get PlotData from FitResult.

plot_ce(ax)

Plot data.

plot_corner([params, color, bins, ...])

Corner plot of bootstrap parameters.

plot_folded(ax)

Plot folded model.

plot_gof()

Plot distribution of GOF statistics and p-value.

plot_pit([detrend])

Probability integral transformation empirical CDF plot.

plot_qq([rtype, seed, detrend])

Quantile-Quantile plot.

plot_residuals(ax[, rtype])

Plot residuals.

plot_spec([data, ne, ene, eene, residuals, ...])

Spectral plot.

plot_unfolded(ax, mtype[, params, egrid, ...])

Plot unfolded model.

set_colors([colors])

Specify the colors of data points used in the plots.

set_xlabel

static get_plot_data(result: MLEResult) dict[str, MLEPlotData][source]#

Get PlotData from FitResult.

plot_corner(params: str | Sequence[str] | None = None, color: str | None = None, bins: int | Sequence[int] = 40, hist_bin_factor: float | Sequence[float] = 1.5, fig_path: str | None = None) Figure[source]#

Corner plot of bootstrap parameters.

Parameters:
paramsstr or sequence of str, optional

Parameters to plot. The default is all spectral parameters.

colorstr, optional

Color of the plot. The default is None.

binsint or list of int, optional

The number of bins to use in histograms, either as a fixed value for all dimensions or as a list of integers for each dimension. The default is 40.

hist_bin_factorfloat or list of float, optional

This is a factor (or list of factors, one for each dimension) that will multiply the bin specifications when making the 1-D histograms. This is generally used to increase the number of bins in the 1-D plots to provide more resolution. The default is 1.5.

fig_pathstr, optional

Path to save the figure. The default is None.

Returns:
Figure

The Figure object containing corner plot.

class PosteriorResultPlotter(result: FitResult, config: PlotConfig = None)[source]#

Bases: Plotter

Attributes

colors

Plotting color for each data.

comps_latex

LaTeX representation of components.

config

Plotting configuration.

ndata

Data points number.

params_labels

Label of parameters.

params_latex

LaTeX representation of parameters.

params_titles

Title of parameters.

params_unit

Unit of parameters.

data

Methods

__call__([plots])

Plot Bayesian fit results.

get_plot_data(result)

Get PlotData from FitResult.

plot_ce(ax)

Plot data.

plot_corner([params, color, divergences, ...])

Corner plot of posterior parameters.

plot_folded(ax)

Plot folded model.

plot_gof()

Plot distribution of GOF statistics and p-value.

plot_khat()

Plot k-hat diagnostic of PSIS-LOO.

plot_pit([detrend])

Probability integral transformation empirical CDF plot.

plot_qq([rtype, seed, detrend])

Quantile-Quantile plot.

plot_residuals(ax[, rtype])

Plot residuals.

plot_spec([data, ne, ene, eene, residuals, ...])

Spectral plot.

plot_trace([params, fig_path])

Plot trace plot of posterior samples.

plot_unfolded(ax, mtype[, params, egrid, ...])

Plot unfolded model.

set_colors([colors])

Specify the colors of data points used in the plots.

set_xlabel

static get_plot_data(result: PosteriorResult) dict[str, PosteriorPlotData][source]#

Get PlotData from FitResult.

plot_trace(params: str | Sequence[str] | None = None, fig_path: str | None = None) Figure[source]#

Plot trace plot of posterior samples.

Parameters:
paramsstr or sequence of str, optional

Parameters to plot. The default is all spectral parameters.

fig_pathstr, optional

Path to save the figure. The default is None.

plot_corner(params: str | Sequence[str] | None = None, color: str | None = None, divergences: bool = True, bins: int | Sequence[int] = 40, hist_bin_factor: float | Sequence[float] = 1.5, fig_path: str | None = None) Figure[source]#

Corner plot of posterior parameters.

Parameters:
paramsstr or sequence of str, optional

Parameters to plot. The default is all spectral parameters.

colorstr, optional

Color of the plot. The default is None.

divergencesbool, optional

Whether to show divergent samples. The default is True.

binsint or list of int, optional

The number of bins to use in histograms, either as a fixed value for all dimensions, or as a list of integers for each dimension. The default is 40.

hist_bin_factorfloat or list of float, optional

This is a factor (or list of factors, one for each dimension) that will multiply the bin specifications when making the 1-D histograms. This is generally used to increase the number of bins in the 1-D plots to provide more resolution. The default is 1.5.

fig_pathstr, optional

Path to save the figure. The default is None.

Returns:
Figure

The Figure object containing corner plot.

plot_khat() Figure[source]#

Plot k-hat diagnostic of PSIS-LOO.