MMMPlotSuite.channel_parameter#
- MMMPlotSuite.channel_parameter(param_name, orient='h', dims=None, figsize=(10, 6))[source]#
Plot the posterior distribution of a channel parameter using violin plots.
Creates violin plots showing the posterior distribution of a parameter for each channel. Handles both channel-indexed parameters (with a “channel” dimension) and scalar parameters gracefully. If additional dimensions are present beyond chain, draw, and channel, creates a subplot for each combination.
- Parameters:
- param_name
str The name of the parameter to plot from posterior. Examples include “saturation_alpha”, “saturation_lam”, “adstock_alpha”.
- orient
str, optional Orientation of the violin plot. Either “h” (horizontal) or “v” (vertical). Default is “h”.
- dims
dict[str,str|int|list], optional Dimension filters to apply. Example: {“geo”: “US”, “country”: [“A”, “B”]}. If provided, only the selected slice(s) will be plotted.
- figsize
tuple[float,float], optional The size of each subplot. Default is (10, 6).
- param_name
- Returns:
- fig
matplotlib.figure.Figure The Figure object containing the plot.
- fig
- Raises:
ValueErrorIf
param_nameis not found in the posterior. If no posterior data is found in idata.
Examples
Plot posterior distribution of saturation alpha parameter:
fig = mmm.plot.channel_parameter(param_name="saturation_alpha")
Plot with dimension filtering:
fig = mmm.plot.channel_parameter( param_name="saturation_alpha", dims={"geo": "US"} )
Plot with vertical orientation:
fig = mmm.plot.channel_parameter( param_name="adstock_alpha", orient="v", figsize=(8, 10) )
Add reference lines after plotting:
fig = mmm.plot.channel_parameter(param_name="saturation_alpha") ax = fig.axes[0] ax.axvline(x=0.5, color="red", linestyle="--", label="reference") ax.legend()