Plots
plots
Visualizations and plot generation utilities for multi-factor interactions.
This module provides standard plotting wrappers, such as plot_interaction_heatmap, to map
the presence and magnitude of interactions across high-dimensional experimental spaces.
| FUNCTION | DESCRIPTION |
|---|---|
plot_interaction_heatmap |
Generates an interaction term heatmap using matplotlib. |
plot_interaction_effects |
Plots interaction effects between a treatment and a covariate on a metric. |
plot_interaction_heatmap
plot_interaction_heatmap(
df_interactions: DataFrame,
annot: Optional[bool] = None,
ax: Optional[Axes] = None,
**kwargs
) -> tuple
Generates an interaction term heatmap using matplotlib.
Visualizes a symmetric matrix of feature/factor interactions. Heatmaps are a highly effective diagnostic chart for screening complex multi-factor studies or high-dimensional covariate sets, allowing the user to instantly recognize clusters of strong synergy or severe interference.
Matrix Structure
Let \(F = \{f_1, f_2, \dots, f_m\}\) be the set of analyzed factors or covariates. The plotting engine constructs
a symmetric \(m \times m\) matrix \(H\):
- Cell \(H_{i,j}\) contains the strength of the interaction between \(f_i\) and \(f_j\). This value can represent
either:
1. The absolute regression interaction coefficient (\(|\beta_{\text{interaction}}|\)).
2. The model-agnostic Friedman's H-statistic (\(H_{ij}\)).
3. The statistical significance transformed index (\(-\log_{10}(p_{\text{value}})\)).
- Cells along the diagonal (\(H_{i,i}\)) are typically zeroed or set to represent the main effect of factor \(f_i\).
- The matrix is rendered using a divergent colormap (such as RdBu or seismic if mapping positive/negative coefficients)
or a sequential colormap (such as Viridis or YlOrRd if mapping absolute H-statistics or significance).
| PARAMETER | DESCRIPTION |
|---|---|
df_interactions
|
A rectangular or pivoted DataFrame representing the interaction strength matrix, with factor names as both index and column headings.
TYPE:
|
annot
|
Whether to annotate the cells with numeric values. If None, annotations are enabled automatically only if the matrix size is small (e.g., <= 20 features).
TYPE:
|
ax
|
Pre-existing axes for the plot. If None, a new figure and axes are created.
TYPE:
|
**kwargs
|
Additional keyword arguments to pass to
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
A tuple
TYPE:
|
Source code in src\xpyrment\interactions\plots.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
plot_interaction_effects
plot_interaction_effects(
data: DataFrame,
treatment_col: str,
metric_col: str,
covariate_col: str,
ax: Optional[Axes] = None,
**kwargs
) -> tuple
Plots interaction effects between a treatment and a covariate on a metric.
Generates a line plot showing the average metric value for different treatment groups across levels of the covariate. This helps visualize if the treatment effect varies depending on the covariate value (heterogeneous treatment effect).
Example
| PARAMETER | DESCRIPTION |
|---|---|
data
|
The experimental data containing treatments, covariates, and metrics.
TYPE:
|
treatment_col
|
The name of the column representing the treatment group.
TYPE:
|
metric_col
|
The name of the column representing the outcome metric.
TYPE:
|
covariate_col
|
The name of the column representing the interacting covariate.
TYPE:
|
ax
|
Pre-existing axes for the plot. If None, a new figure and axes are created.
TYPE:
|
**kwargs
|
Additional keyword arguments to pass to the underlying plotting functions.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
A tuple
TYPE:
|
Source code in src\xpyrment\interactions\plots.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |