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:
- var
str The name of the variable to plot from posterior.
- plot_dim
str, optional The dimension to plot distributions over. Default is “channel”. This dimension will be used as the categorical axis for the violin plots.
- orient
str, optional Orientation of the plot. Either “h” (horizontal) or “v” (vertical). Default is “h”.
- dims
dict[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.
- figsize
tuple[float,float], optional The size of each subplot. Default is (10, 6).
- var
- Returns:
- fig
matplotlib.figure.Figure The Figure object containing the subplots.
- axes
np.ndarrayofmatplotlib.axes.Axes Array of Axes objects corresponding to each subplot.
- fig
- Raises:
ValueErrorIf
varis not found in the posterior. Ifplot_dimis 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")