causalis.shared.outcome_plots¶
Module Contents¶
Functions¶
Plot the distribution of the outcome for each treatment on a single, pretty plot. |
|
Prettified boxplot of the outcome by treatment. |
|
Plot the distribution of the outcome for every treatment on one plot, and also produce a boxplot by treatment to visualize outliers. |
API¶
- causalis.shared.outcome_plots.outcome_plot_dist(data: Union[causalis.dgp.causaldata.CausalData, causalis.dgp.multicausaldata.MultiCausalData], treatment: Optional[str] = None, outcome: Optional[str] = None, bins: Union[str, int] = 'fd', density: bool = True, alpha: float = 0.45, sharex: bool = True, kde: bool = True, clip: Optional[Tuple[float, float]] = (0.01, 0.99), figsize: Tuple[float, float] = (9, 5.5), dpi: int = 220, font_scale: float = 1.15, palette: Optional[Union[list, dict]] = None, save: Optional[str] = None, save_dpi: Optional[int] = None, transparent: bool = False) → matplotlib.pyplot.Figure¶
Plot the distribution of the outcome for each treatment on a single, pretty plot.
Features
High-DPI canvas + scalable fonts
Default Matplotlib colors; KDE & mean lines match their histogram colors
Numeric outcomes: shared x-range (optional), optional KDE, quantile clipping
Categorical outcomes: normalized grouped bars by treatment
Binary outcomes: proportion bars with percent labels (no KDE)
Optional hi-res export (PNG/SVG/PDF)
Parameters
data : CausalData or MultiCausalData The causal dataset containing the dataframe and metadata. treatment : str, optional Treatment column name. For MultiCausalData, if not provided, one-hot treatment columns are converted to assigned treatment labels. outcome : str, optional Outcome column name. Defaults to the one in
data_contracts. bins : str or int, default “fd” Number of bins for histograms (e.g., “fd”, “auto”, or an integer). density : bool, default True Whether to normalize histograms to form a density. alpha : float, default 0.45 Transparency for overlaid histograms and bars. sharex : bool, default True If True, use the same x-limits across treatments for numeric outcomes. kde : bool, default True Whether to overlay a smooth density (KDE) for numeric outcomes. clip : tuple, optional, default (0.01, 0.99) Quantiles to trim tails for nicer view of numeric outcomes. figsize : tuple, default (9, 5.5) Figure size in inches (width, height). dpi : int, default 220 Dots per inch for the figure. font_scale : float, default 1.15 Scaling factor for all font sizes in the plot. palette : list or dict, optional Color palette for treatments (list in treatment order or dict {treatment: color}). save : str, optional Path to save the figure (e.g., “outcome.png”). save_dpi : int, optional DPI for the saved figure. Defaults to 300 for raster formats. transparent : bool, default False Whether to save the figure with a transparent background.Returns
matplotlib.figure.Figure The generated figure object.
- causalis.shared.outcome_plots.outcome_plot_boxplot(data: Union[causalis.dgp.causaldata.CausalData, causalis.dgp.multicausaldata.MultiCausalData], treatment: Optional[str] = None, outcome: Optional[str] = None, figsize: Tuple[float, float] = (9, 5.5), dpi: int = 220, font_scale: float = 1.15, showfliers: bool = True, patch_artist: bool = True, palette: Optional[Union[list, dict]] = None, save: Optional[str] = None, save_dpi: Optional[int] = None, transparent: bool = False) → matplotlib.pyplot.Figure¶
Prettified boxplot of the outcome by treatment.
Features
High-DPI figure, scalable fonts
Soft modern color styling (default Matplotlib palette)
Optional outliers, gentle transparency
Optional save to PNG/SVG/PDF
Parameters
data : CausalData or MultiCausalData The causal dataset containing the dataframe and metadata. treatment : str, optional Treatment column name. For MultiCausalData, if not provided, one-hot treatment columns are converted to assigned treatment labels. outcome : str, optional Outcome column name. Defaults to the one in
data_contracts. figsize : tuple, default (9, 5.5) Figure size in inches (width, height). dpi : int, default 220 Dots per inch for the figure. font_scale : float, default 1.15 Scaling factor for all font sizes in the plot. showfliers : bool, default True Whether to show outliers (fliers). patch_artist : bool, default True Whether to fill boxes with color. palette : list or dict, optional Color palette for treatments (list in treatment order or dict {treatment: color}). save : str, optional Path to save the figure (e.g., “boxplot.png”). save_dpi : int, optional DPI for the saved figure. Defaults to 300 for raster formats. transparent : bool, default False Whether to save the figure with a transparent background.Returns
matplotlib.figure.Figure The generated figure object.
- causalis.shared.outcome_plots.outcome_plots(data: Union[causalis.dgp.causaldata.CausalData, causalis.dgp.multicausaldata.MultiCausalData], treatment: Optional[str] = None, outcome: Optional[str] = None, bins: int = 30, density: bool = True, alpha: float = 0.5, figsize: Tuple[float, float] = (7, 4), sharex: bool = True, palette: Optional[Union[list, dict]] = None) → Tuple[matplotlib.pyplot.Figure, matplotlib.pyplot.Figure]¶
Plot the distribution of the outcome for every treatment on one plot, and also produce a boxplot by treatment to visualize outliers.
Parameters
data : CausalData or MultiCausalData The causal dataset containing the dataframe and metadata. treatment : str, optional Treatment column name. Defaults to the one in
data_contracts. outcome : str, optional Outcome column name. Defaults to the one indata_contracts. bins : int, default 30 Number of bins for histograms when the outcome is numeric. density : bool, default True Whether to normalize histograms to form a density. alpha : float, default 0.5 Transparency for overlaid histograms. figsize : tuple, default (7, 4) Figure size for the plots (width, height). sharex : bool, default True If True and the outcome is numeric, use the same x-limits across treatments. palette : list or dict, optional Color palette for treatments (list in treatment order or dict {treatment: color}).Returns
Tuple[matplotlib.figure.Figure, matplotlib.figure.Figure] (fig_distribution, fig_boxplot)