"""
closuretest/plots.py
Plots of statistical estimators for closure tests
"""
from reportengine.figure import figure
from validphys import plotutils
[docs]
@figure
def plot_biases(biases_table):
"""
Plot the bias of each experiment for all fits with bars. For information on
how biases is calculated see `bias_experiment`
"""
fig, ax = plotutils.barplot(
biases_table.values.T,
collabels=biases_table.index.values,
datalabels=biases_table.columns.droplevel(1).values,
)
ax.set_title("Biases per experiment for each fit")
ax.legend()
return fig
[docs]
@figure
def plot_delta_chi2(delta_chi2_bootstrap, fits):
"""Plots distributions of delta chi2 for each fit in `fits`.
Distribution is generated by bootstrapping. For more information
on delta chi2 see `delta_chi2_bootstrap`
"""
delta_chi2 = delta_chi2_bootstrap.T
labels = [fit.label for fit in fits]
fig, ax = plotutils.subplots()
for i, label in enumerate(labels):
ax.hist(delta_chi2[:, i], alpha=0.3, label=label, zorder=100)
ax.set_xlabel(r"$\Delta_{\chi^{2}}$")
l = ax.legend()
l.set_zorder(1000)
ax.set_title(r"Total $\Delta_{\chi^{2}}$ for each fit")
return fig
[docs]
@figure
def plot_fits_bootstrap_variance(fits_bootstrap_variance_table):
"""Plot variance as error bars, with mean and central value calculated
from bootstrap sample
"""
fig, ax = errorbar_figure_from_table(fits_bootstrap_variance_table)
ax.set_title("Variance by experiment for closure fits")
return fig
[docs]
@figure
def plot_fits_bootstrap_bias(fits_bootstrap_bias_table):
"""Plot the bias for each experiment for all `fits` as a point with an error bar,
where the error bar is given by bootstrapping the bias across replicas
The number of bootstrap samples can be controlled by the parameter `bootstrap_samples`
"""
fig, ax = errorbar_figure_from_table(fits_bootstrap_bias_table)
ax.set_title("Bias by experiment for closure fits")
return fig