Visualizations¶
Helper functions to visualize results of ABCSMC runs.

pyabc.visualization.
kde_1d
(df, w, x, xmin=None, xmax=None, numx=50)¶ Calculates a 1 dimensional histogram from a Dataframe and weights.
For example, a results distribution might be obtained from the history class and plotted as follows:
df, w = history.get_distribution(0) x, pdf = hist_2d(df, w, "x") plt.plot(x, pdf)
Parameters:  df (Pandas Dataframe) – The rows are the observations, the columns the variables
 w (np.ndarray) – The corresponding weights
 x (str) – The variable for the xaxis
 xmin (float, optional) – The lower limit in x for the histogram. If left empty, it is set to the minimum of the ovbservations of the variable to be plotted as x.
 xmax (float, optional) – The upper limit in x for the histogram. If left empty, it is set to the maximum of the ovbservations of the variable to be plotted as x.
 numx (int, optional) – The number of bins in x direction. Defaults to 50.
Returns: x, pdf – The x and the densities at these points. These can be passed for plotting, for example as plt.plot(x, pdf)
Return type: (np.ndarray, np.ndarray)

pyabc.visualization.
kde_2d
(df, w, x, y, xmin=None, xmax=None, ymin=None, ymax=None, numx=50, numy=50)¶ Calculates a 2 dimensional histogram from a Dataframe and weights.
For example, a results distribution might be obtained from the history class and plotted as follows:
df, w = history.get_distribution(0) X, Y, PDF = hist_2d(df, w, "x", "y") plt.pcolormesh(X, Y, PDF)
Parameters:  df (Pandas Dataframe) – The rows are the observations, the columns the variables
 w (The corresponding weights) –
 x (str) – The variable for the xaxis
 y (str) – The variable for the yaxis
 xmin (float, optional) – The lower limit in x for the histogram. If left empty, it is set to the minimum of the ovbservations of the variable to be plotted as x.
 xmax (float, optional) – The upper limit in x for the histogram. If left empty, it is set to the maximum of the ovbservations of the variable to be plotted as x.
 ymin (float, optional) – The lower limit in y for the histogram. If left empty, it is set to the minimum of the ovbservations of the variable to be plotted as y
 ymax (float, optional) – The upper limit in y for the histogram. If left empty, it is set to the maximum of the ovbservations of the variable to be plotted as y.
 numx (int, optional) – The number of bins in x direction. Defaults tp 50.
 int, optional (numy) – The number of bins in y direction. Defaults tp 50.
Returns: X, Y, PDF – The X, the Y and the densities at these points. These can be passed for plotting, for example as plt.pcolormesh(X, Y, PDF)
Return type: (np.ndarray, np.ndarray, np.ndarray)

pyabc.visualization.
plot_kde_1d
(df, w, x, xmin=None, xmax=None, numx=50, ax=None, refval=None, **kwargs)¶ Plots a 1d histogram.
Parameters:  df (Pandas Dataframe) – The rows are the observations, the columns the variables
 w (The corresponding weights) –
 x (str) – The variable for the xaxis
 xmin (float, optional) – The lower limit in x for the histogram. If left empty, it is set to the minimum of the ovbservations of the variable to be plotted as x.
 xmax (float, optional) – The upper limit in x for the histogram. If left empty, it is set to the maximum of the ovbservations of the variable to be plotted as x.
 numx (int, optional) – The number of bins in x direction. Defaults tp 50.
 refval (dict, optional) – A reference value for x (as refval[x]: float). If not None, the value will be highlighted in the plot. Default: None.
Returns: ax – axis of the plot
Return type: matplotlib axis

pyabc.visualization.
plot_kde_2d
(df, w, x, y, xmin=None, xmax=None, ymin=None, ymax=None, numx=50, numy=50, ax=None, colorbar=True, title=True, refval=None, **kwargs)¶ Plots a 2d histogram.
Parameters:  df (Pandas Dataframe) – The rows are the observations, the columns the variables
 w (The corresponding weights.) –
 x (str) – The variable for the xaxis.
 y (str) – The variable for the yaxis.
 xmin (float, optional) – The lower limit in x for the histogram. If left empty, it is set to the minimum of the ovbservations of the variable to be plotted as x.
 xmax (float, optional) – The upper limit in x for the histogram. If left empty, it is set to the maximum of the ovbservations of the variable to be plotted as x.
 ymin (float, optional) – The lower limit in y for the histogram. If left empty, it is set to the minimum of the ovbservations of the variable to be plotted as y.
 ymax (float, optional) – The upper limit in y for the histogram. If left empty, it is set to the maximum of the ovbservations of the variable to be plotted as y.
 numx (int, optional) – The number of bins in x direction. Defaults to 50.
 int, optional (numy) – The number of bins in y direction. Defaults tp 50.
 colorbar (bool, optional) – Whether to plot a colorbar. Defaults to True.
 title (bool, optional) – Whether to put a title on the plot. Defaults to True.
 refval (dict, optional) – A reference parameter to be shown in the plots. Default: None.
Returns: ax – axis of the plot
Return type: matplotlib axis

pyabc.visualization.
plot_kde_matrix
(df, w, limits=None, colorbar=True, refval=None)¶ Plot a KDE matrix.
Parameters:  df (Pandas Dataframe) – The rows are the observations, the columns the variables.
 w (np.narray) – The corresponding weights.
 colorbar (bool) – Whether to plot the colorbars or not.
 limits (dictionary, optional) – Dictionary of the form
{"name": (lower_limit, upper_limit)}
.  refval (dict, optional) – A reference parameter to be shown in the plots (e.g. the underlying ground truth parameter used to simulate the data for testing purposes). Default: None.