MMMPlotlyFactory#

class pymc_marketing.mmm.plot_interactive.MMMPlotlyFactory(summary)[source]#

Factory for creating interactive Plotly plots from MMM summary data.

This class provides methods for visualizing MMM results using Plotly, with automatic support for both Pandas and Polars DataFrames via Narwhals.

Parameters:
summaryMMMSummaryFactory

Summary factory that provides access to data and model

Attributes:
custom_dimslist[str]

Get custom dimensions from summary factory.

Methods

contributions(hdi_prob, component, frequency, …)

Bar chart of channel/control/seasonality contributions

roas(hdi_prob, frequency, …)

Bar chart of Return on Ad Spend metrics

posterior_predictive(hdi_prob, frequency, …)

Time series comparing actual vs predicted with HDI bands

saturation_curves(hdi_prob, max_value, …)

Line plots showing diminishing returns per channel

adstock_curves(hdi_prob, amount, …)

Line plots showing carryover effects over time

See also

MMMSummaryFactory

Data factory providing summary statistics

MMMPlotSuite

Static matplotlib plotting functionality

Examples

Access via fitted MMM model

>>> # Basic posterior predictive plot
>>> fig = mmm.plot_interactive.posterior_predictive()
>>> fig.show()
>>> # Channel contributions with default settings
>>> fig = mmm.plot_interactive.contributions()
>>> fig.show()
>>> # ROAS aggregated yearly, colored by date
>>> fig = mmm.plot_interactive.roas(frequency="yearly", color="date", x="channel")
>>> fig.show()

Controlling faceting behavior

For models with custom dimensions (geo, brand, etc.), auto_facet=True (default) automatically creates subplots for each dimension combination.

>>> # Auto-facet enabled (default): creates subplots automatically
>>> fig = mmm.plot_interactive.saturation_curves()
>>> fig.show()
>>> # Disable auto-facet and manually control faceting
>>> fig = mmm.plot_interactive.saturation_curves(
...     facet_row="brand", auto_facet=False
... )
>>> fig.show()
>>> # Use facet_col instead of facet_row
>>> fig = mmm.plot_interactive.saturation_curves(facet_col="brand", auto_facet=True)
>>> fig.show()

Customizing appearance with Plotly kwargs

Any additional keyword arguments are passed directly to Plotly Express:

>>> fig = mmm.plot_interactive.contributions(
...     title="My Custom Title",
...     height=600,
...     width=1000,
...     color_discrete_sequence=["red", "blue", "green"],
... )
>>> fig.show()

Methods

MMMPlotlyFactory.__init__(summary)

Initialize the plotting factory.

MMMPlotlyFactory.adstock_curves([hdi_prob, ...])

Plot adstock/decay curves by channel.

MMMPlotlyFactory.contributions([hdi_prob, ...])

Plot contributions bar chart with optional error bars and faceting.

MMMPlotlyFactory.posterior_predictive([...])

Plot posterior predictive with HDI band.

MMMPlotlyFactory.roas([hdi_prob, frequency, ...])

Plot ROAS (Return on Ad Spend) bar chart.

MMMPlotlyFactory.saturation_curves([...])

Plot saturation curves by channel.

Attributes

custom_dims

Get custom dimensions from summary factory.