MMMPlotSuite.posterior_distribution#

MMMPlotSuite.posterior_distribution(var, plot_dim='channel', orient='h', dims=None, figsize=(10, 6))[source]#

Plot the posterior distribution of a variable across a specified dimension.

Creates violin plots showing the posterior distribution of a parameter for each value in the specified dimension (e.g., each channel). If additional dimensions are present, creates a subplot for each combination.

Parameters:
varstr

The name of the variable to plot from posterior.

plot_dimstr, optional

The dimension to plot distributions over. Default is “channel”. This dimension will be used as the categorical axis for the violin plots.

orientstr, optional

Orientation of the plot. Either “h” (horizontal) or “v” (vertical). Default is “h”.

dimsdict[str, str | int | list], optional

Dimension filters to apply. Example: {“geo”: “US”, “channel”: [“TV”, “Radio”]}. If provided, only the selected slice(s) will be plotted.

figsizetuple[float, float], optional

The size of each subplot. Default is (10, 6).

Returns:
figmatplotlib.figure.Figure

The Figure object containing the subplots.

axesnp.ndarray of matplotlib.axes.Axes

Array of Axes objects corresponding to each subplot.

Raises:
ValueError

If var is not found in the posterior. If plot_dim is not a dimension of the variable. If no posterior data is found in idata.

Examples

Plot posterior distribution of a saturation parameter:

mmm.plot.posterior_distribution(var="lam", plot_dim="channel")

Plot with dimension filtering:

mmm.plot.posterior_distribution(
    var="lam", plot_dim="channel", dims={"geo": "US"}
)

Plot vertical orientation:

mmm.plot.posterior_distribution(var="alpha", plot_dim="channel", orient="v")