stplot 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. stplot/__init__.py +21 -0
  2. stplot/config/__init__.py +33 -0
  3. stplot/config/loader.py +106 -0
  4. stplot/config/models.py +328 -0
  5. stplot/config/presets/__init__.py +1 -0
  6. stplot/config/presets/default.yaml +208 -0
  7. stplot/config/presets/horizons_one_plan.yaml +59 -0
  8. stplot/io/__init__.py +6 -0
  9. stplot/io/spatial.py +72 -0
  10. stplot/io/tabular.py +154 -0
  11. stplot/plots/__init__.py +122 -0
  12. stplot/plots/barbell.py +400 -0
  13. stplot/plots/batch.py +135 -0
  14. stplot/plots/domains.py +1143 -0
  15. stplot/plots/executive.py +474 -0
  16. stplot/plots/export.py +74 -0
  17. stplot/plots/infographics.py +1118 -0
  18. stplot/plots/lollipop.py +285 -0
  19. stplot/plots/maps.py +738 -0
  20. stplot/plots/matrix.py +190 -0
  21. stplot/plots/one_plan.py +642 -0
  22. stplot/plots/paired.py +437 -0
  23. stplot/plots/scorecards.py +1940 -0
  24. stplot/plots/state.py +373 -0
  25. stplot/plots/state_trends.py +1413 -0
  26. stplot/plots/tables.py +107 -0
  27. stplot/plots/timeseries.py +607 -0
  28. stplot/plots/trends.py +305 -0
  29. stplot/reporting/__init__.py +24 -0
  30. stplot/reporting/captions.py +177 -0
  31. stplot/reporting/html_companion.py +339 -0
  32. stplot/reporting/templates.py +485 -0
  33. stplot/reporting/word.py +369 -0
  34. stplot/theme/__init__.py +25 -0
  35. stplot/theme/folium.py +62 -0
  36. stplot/theme/mpl.py +181 -0
  37. stplot/theme/plotly.py +130 -0
  38. stplot/transform/__init__.py +60 -0
  39. stplot/transform/categories.py +51 -0
  40. stplot/transform/columns.py +103 -0
  41. stplot/transform/filters.py +385 -0
  42. stplot/transform/merge.py +173 -0
  43. stplot/transform/pairing.py +154 -0
  44. stplot/transform/qa.py +297 -0
  45. stplot/transform/tables.py +573 -0
  46. stplot/transform/zones.py +354 -0
  47. stplot-0.1.0.dist-info/METADATA +235 -0
  48. stplot-0.1.0.dist-info/RECORD +49 -0
  49. stplot-0.1.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,642 @@
1
+ """Horizons One Plan Pass/Fail compliance bar chart template."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import math
6
+ import textwrap
7
+ from pathlib import Path
8
+
9
+ import matplotlib.pyplot as plt
10
+ import matplotlib.ticker as mtick
11
+ import numpy as np
12
+ import pandas as pd
13
+ from matplotlib.axes import Axes
14
+ from matplotlib.figure import Figure
15
+ from matplotlib.lines import Line2D
16
+
17
+ from stplot.config import Config, ensure_config, resolve_column, resolve_palette
18
+ from stplot.theme.mpl import mpl_theme, style_axes
19
+ from stplot.transform.columns import validate_columns
20
+ from stplot.transform.filters import derive_pass_fail
21
+
22
+
23
+ def pass_fail_bar(
24
+ df: pd.DataFrame,
25
+ *,
26
+ group_col: str | None = None,
27
+ result_col: str | None = None,
28
+ pass_label: str = "Pass",
29
+ fail_label: str = "Fail",
30
+ min_label_pct: float = 4.0,
31
+ show_n: bool = True,
32
+ palette: dict[str, str] | None = None,
33
+ title: str | None = None,
34
+ subtitle: str | None = None,
35
+ xlabel: str | None = "Variable and statistic type",
36
+ ylabel: str | None = "Proportion of sites",
37
+ legend_title: str | None = "Site result",
38
+ x_rotation: float = 40.0,
39
+ figsize: tuple[float, float] | None = None,
40
+ ax: Axes | None = None,
41
+ config: str | Path | Config | None = None,
42
+ ) -> tuple[Figure, Axes]:
43
+ """Plot a 100% stacked vertical Pass/Fail bar chart by variable or criteria.
44
+
45
+ Matches the Horizons One Plan reporting style with ``n = XX`` totals above each bar,
46
+ white bold percentage labels inside segments, a title + subtitle header, and a
47
+ centered horizontal legend above the plot.
48
+
49
+ Required columns (resolved via ``config.columns`` unless explicitly overridden):
50
+ - ``group_col`` (default key: ``"attribute_label"`` if present, else ``"attribute"``)
51
+ - ``result_col`` (default key: ``"state_band"``; boolean columns are automatically
52
+ mapped to ``Pass`` / ``Fail`` via :func:`stplot.transform.derive_pass_fail`)
53
+
54
+ Returns:
55
+ Tuple of ``(fig, ax)``.
56
+ """
57
+ cfg = ensure_config(config if config is not None else "horizons_one_plan")
58
+
59
+ if group_col is not None:
60
+ resolved_group = group_col
61
+ elif "attribute_label" in cfg.columns and cfg.columns["attribute_label"] in df.columns:
62
+ resolved_group = cfg.columns["attribute_label"]
63
+ else:
64
+ resolved_group = resolve_column(None, cfg, "attribute")
65
+
66
+ resolved_result = resolve_column(result_col, cfg, "state_band")
67
+ validate_columns(df, [resolved_group, resolved_result], context="pass_fail_bar")
68
+
69
+ work = df.copy()
70
+ if pd.api.types.is_bool_dtype(work[resolved_result]):
71
+ work = derive_pass_fail(
72
+ work,
73
+ passes_col=resolved_result,
74
+ out_col="_stplot_result",
75
+ pass_label=pass_label,
76
+ fail_label=fail_label,
77
+ include_insufficient=False,
78
+ config=cfg,
79
+ )
80
+ cat_col = "_stplot_result"
81
+ else:
82
+ cat_col = resolved_result
83
+
84
+ work = work[work[cat_col].isin([pass_label, fail_label])]
85
+ counts = pd.crosstab(work[resolved_group], work[cat_col])
86
+ for col_name in (pass_label, fail_label):
87
+ if col_name not in counts.columns:
88
+ counts[col_name] = 0
89
+ counts = counts[[pass_label, fail_label]]
90
+
91
+ totals = counts.sum(axis=1)
92
+ pcts = counts.div(totals.replace(0, pd.NA), axis=0).mul(100.0).fillna(0.0)
93
+
94
+ resolved_palette = resolve_palette(palette, cfg, "state_bands")
95
+ colors = [
96
+ resolved_palette.get(pass_label, "#2e8b57"),
97
+ resolved_palette.get(fail_label, "#d95f59"),
98
+ ]
99
+
100
+ with mpl_theme(cfg):
101
+ if ax is None:
102
+ fig, ax = plt.subplots(figsize=figsize or (12.0, 6.2))
103
+ else:
104
+ fig = ax.figure # type: ignore[assignment]
105
+
106
+ x_positions = range(len(pcts.index))
107
+ pass_vals = pcts[pass_label].to_numpy()
108
+ fail_vals = pcts[fail_label].to_numpy()
109
+
110
+ ax.bar(
111
+ x_positions,
112
+ pass_vals,
113
+ color=colors[0],
114
+ width=0.72,
115
+ edgecolor=cfg.theme.background_color,
116
+ linewidth=0.8,
117
+ label=pass_label,
118
+ )
119
+ ax.bar(
120
+ x_positions,
121
+ fail_vals,
122
+ bottom=pass_vals,
123
+ color=colors[1],
124
+ width=0.72,
125
+ edgecolor=cfg.theme.background_color,
126
+ linewidth=0.8,
127
+ label=fail_label,
128
+ )
129
+
130
+ # In-bar percentage labels and top n = XX annotations
131
+ for idx, (p_val, f_val, n_total) in enumerate(
132
+ zip(pass_vals, fail_vals, totals.to_numpy(), strict=True)
133
+ ):
134
+ if p_val >= min_label_pct:
135
+ ax.text(
136
+ idx,
137
+ p_val / 2.0,
138
+ f"{p_val:.0f}%",
139
+ ha="center",
140
+ va="center",
141
+ color="#ffffff",
142
+ fontsize=max(cfg.theme.tick_size - 1, 8),
143
+ fontweight="bold",
144
+ )
145
+ if f_val >= min_label_pct:
146
+ ax.text(
147
+ idx,
148
+ p_val + f_val / 2.0,
149
+ f"{f_val:.0f}%",
150
+ ha="center",
151
+ va="center",
152
+ color="#ffffff",
153
+ fontsize=max(cfg.theme.tick_size - 1, 8),
154
+ fontweight="bold",
155
+ )
156
+ if show_n:
157
+ ax.text(
158
+ idx,
159
+ 102.0,
160
+ f"n = {int(n_total)}",
161
+ ha="center",
162
+ va="bottom",
163
+ color=cfg.theme.text_color,
164
+ fontsize=max(cfg.theme.tick_size - 1, 8),
165
+ )
166
+
167
+ ax.set_xticks(list(x_positions))
168
+ ax.set_xticklabels(
169
+ [str(label) for label in pcts.index],
170
+ rotation=x_rotation,
171
+ ha="right" if x_rotation else "center",
172
+ )
173
+ ax.set_ylim(0, 108 if show_n else 102)
174
+ ax.set_yticks(range(0, 101, 10))
175
+ ax.yaxis.set_major_formatter(mtick.PercentFormatter(xmax=100, decimals=0))
176
+
177
+ style_axes(ax, title=None, xlabel=xlabel, ylabel=ylabel, config=cfg)
178
+ ax.xaxis.grid(False)
179
+
180
+ ax.legend(
181
+ title=legend_title,
182
+ loc="upper center",
183
+ bbox_to_anchor=(0.5, 1.15),
184
+ ncol=2,
185
+ frameon=False,
186
+ fontsize=cfg.theme.legend_size,
187
+ title_fontsize=cfg.theme.legend_size,
188
+ )
189
+
190
+ if title or subtitle:
191
+ if title:
192
+ ax.text(
193
+ 0.5,
194
+ 1.24 if subtitle else 1.19,
195
+ title,
196
+ transform=ax.transAxes,
197
+ ha="center",
198
+ va="bottom",
199
+ fontsize=cfg.theme.title_size,
200
+ color=cfg.theme.text_color,
201
+ fontweight=cfg.theme.title_weight,
202
+ )
203
+ if subtitle:
204
+ ax.text(
205
+ 0.5,
206
+ 1.18,
207
+ subtitle,
208
+ transform=ax.transAxes,
209
+ ha="center",
210
+ va="bottom",
211
+ fontsize=cfg.theme.subtitle_size,
212
+ color=cfg.theme.text_color,
213
+ )
214
+
215
+ return fig, ax
216
+
217
+
218
+ def pass_fail_donuts(
219
+ df: pd.DataFrame,
220
+ *,
221
+ group_col: str | None = None,
222
+ result_col: str | None = None,
223
+ pass_label: str = "Pass",
224
+ fail_label: str = "Fail",
225
+ ncols: int = 3,
226
+ palette_key: str = "one_plan_report",
227
+ palette: dict[str, str] | None = None,
228
+ title: str | None = None,
229
+ caption: str | None = None,
230
+ small_slice_pct: float = 8.0,
231
+ figsize: tuple[float, float] | None = None,
232
+ config: str | Path | Config | None = None,
233
+ ) -> tuple[Figure, list[Axes]]:
234
+ """Plot a small-multiple grid of Pass/Fail donut charts with centered indicator labels.
235
+
236
+ Matches the Horizons One Plan executive report style: cyan/dark-slate donuts,
237
+ wrapped indicator names centered inside each ring, bold white percentage labels
238
+ inside large wedges and outside callouts for small wedges, plus a shared legend.
239
+
240
+ Returns:
241
+ Tuple of ``(fig, axes_list)``.
242
+ """
243
+ cfg = ensure_config(config if config is not None else "horizons_one_plan")
244
+
245
+ if group_col is not None:
246
+ resolved_group = group_col
247
+ elif "attribute_label" in cfg.columns and cfg.columns["attribute_label"] in df.columns:
248
+ resolved_group = cfg.columns["attribute_label"]
249
+ else:
250
+ resolved_group = resolve_column(None, cfg, "attribute")
251
+
252
+ resolved_result = resolve_column(result_col, cfg, "state_band")
253
+ validate_columns(df, [resolved_group, resolved_result], context="pass_fail_donuts")
254
+
255
+ work = df.copy()
256
+ if pd.api.types.is_bool_dtype(work[resolved_result]):
257
+ work = derive_pass_fail(
258
+ work,
259
+ passes_col=resolved_result,
260
+ out_col="_stplot_result",
261
+ pass_label=pass_label,
262
+ fail_label=fail_label,
263
+ include_insufficient=False,
264
+ config=cfg,
265
+ )
266
+ cat_col = "_stplot_result"
267
+ else:
268
+ cat_col = resolved_result
269
+
270
+ work = work[work[cat_col].isin([pass_label, fail_label])]
271
+ counts = pd.crosstab(work[resolved_group], work[cat_col])
272
+ for col_name in (pass_label, fail_label):
273
+ if col_name not in counts.columns:
274
+ counts[col_name] = 0
275
+ counts = counts[[pass_label, fail_label]]
276
+
277
+ resolved_palette = (
278
+ dict(palette)
279
+ if palette is not None
280
+ else cfg.palettes.get(palette_key, resolve_palette(None, cfg, "state_bands"))
281
+ )
282
+ pass_color = resolved_palette.get(pass_label, "#009ec2")
283
+ fail_color = resolved_palette.get(fail_label, "#263742")
284
+
285
+ groups = list(counts.index)
286
+ n_groups = len(groups)
287
+ n_cols = min(ncols, max(n_groups, 1))
288
+ n_rows = math.ceil(n_groups / n_cols)
289
+
290
+ with mpl_theme(cfg):
291
+ fig_size = figsize or (3.6 * n_cols, 3.6 * n_rows + (0.7 if caption else 0.3))
292
+ fig, axes_grid = plt.subplots(n_rows, n_cols, figsize=fig_size)
293
+ fig.patch.set_facecolor(cfg.theme.background_color)
294
+ axes_flat: list[Axes] = (
295
+ list(np.asarray(axes_grid).ravel()) if n_groups > 1 else [axes_grid] # type: ignore[list-item]
296
+ )
297
+
298
+ for idx, ax in enumerate(axes_flat):
299
+ if idx >= n_groups:
300
+ ax.axis("off")
301
+ continue
302
+
303
+ grp = groups[idx]
304
+ n_pass = float(counts.loc[grp, pass_label])
305
+ n_fail = float(counts.loc[grp, fail_label])
306
+ total = n_pass + n_fail
307
+ pct_pass = 100.0 * n_pass / total if total > 0 else 0.0
308
+ pct_fail = 100.0 * n_fail / total if total > 0 else 0.0
309
+
310
+ vals: list[float] = []
311
+ cols: list[str] = []
312
+ if pct_pass > 0:
313
+ vals.append(pct_pass)
314
+ cols.append(pass_color)
315
+ if pct_fail > 0:
316
+ vals.append(pct_fail)
317
+ cols.append(fail_color)
318
+
319
+ wedges, _ = ax.pie(
320
+ vals,
321
+ colors=cols,
322
+ startangle=90,
323
+ counterclock=False,
324
+ wedgeprops={"width": 0.36, "edgecolor": "none"},
325
+ )
326
+
327
+ for wedge, pct in zip(wedges, vals, strict=True):
328
+ angle = math.radians((wedge.theta1 + wedge.theta2) / 2.0)
329
+ label_txt = (
330
+ f"{pct:.0f}%" if pct >= 99.95 or abs(pct - round(pct)) < 0.05 else f"{pct:.1f}%"
331
+ )
332
+ if pct < small_slice_pct:
333
+ x_pos, y_pos = 1.15 * math.cos(angle), 1.15 * math.sin(angle)
334
+ ax.text(
335
+ x_pos,
336
+ y_pos,
337
+ label_txt,
338
+ ha="center",
339
+ va="center",
340
+ fontsize=cfg.theme.tick_size - 1,
341
+ color=cfg.theme.text_color,
342
+ )
343
+ else:
344
+ r_mid = 0.82
345
+ x_pos, y_pos = r_mid * math.cos(angle), r_mid * math.sin(angle)
346
+ ax.text(
347
+ x_pos,
348
+ y_pos,
349
+ label_txt,
350
+ ha="center",
351
+ va="center",
352
+ fontsize=cfg.theme.tick_size - 1,
353
+ fontweight="bold",
354
+ color="#ffffff",
355
+ )
356
+
357
+ wrapped = "\n".join(textwrap.wrap(str(grp), width=16))
358
+ ax.text(
359
+ 0.0,
360
+ 0.0,
361
+ wrapped,
362
+ ha="center",
363
+ va="center",
364
+ fontsize=cfg.theme.label_size - 0.5,
365
+ fontweight="bold",
366
+ color=cfg.theme.text_color,
367
+ )
368
+ ax.set_aspect("equal")
369
+
370
+ handles = [
371
+ Line2D(
372
+ [0],
373
+ [0],
374
+ marker="o",
375
+ color="w",
376
+ label=fail_label,
377
+ markerfacecolor=fail_color,
378
+ markersize=11,
379
+ ),
380
+ Line2D(
381
+ [0],
382
+ [0],
383
+ marker="o",
384
+ color="w",
385
+ label=pass_label,
386
+ markerfacecolor=pass_color,
387
+ markersize=11,
388
+ ),
389
+ ]
390
+ fig.legend(
391
+ handles=handles,
392
+ loc="lower right",
393
+ bbox_to_anchor=(0.98, 0.14 if caption else 0.04),
394
+ frameon=False,
395
+ fontsize=cfg.theme.legend_size,
396
+ )
397
+
398
+ if title:
399
+ fig.suptitle(
400
+ title,
401
+ fontsize=cfg.theme.title_size,
402
+ fontweight=cfg.theme.title_weight,
403
+ color=cfg.theme.text_color,
404
+ y=0.98,
405
+ )
406
+ if caption:
407
+ fig.text(
408
+ 0.5,
409
+ 0.02,
410
+ caption,
411
+ ha="center",
412
+ va="bottom",
413
+ fontsize=cfg.theme.caption_size,
414
+ color=cfg.theme.caption_color,
415
+ )
416
+
417
+ fig.tight_layout(rect=(0.0, 0.08 if caption else 0.0, 0.94, 0.94 if title else 0.98))
418
+
419
+ return fig, axes_flat
420
+
421
+
422
+ def compliance_dot_matrix(
423
+ df: pd.DataFrame,
424
+ *,
425
+ site_col: str | None = None,
426
+ indicator_col: str | None = None,
427
+ result_col: str | None = None,
428
+ interim_col: str | None = None,
429
+ site_order: list[str] | None = None,
430
+ indicator_order: list[str] | None = None,
431
+ palette_key: str = "one_plan_report",
432
+ palette: dict[str, str] | None = None,
433
+ title: str | None = None,
434
+ caption: str | None = None,
435
+ marker_size: float = 380.0,
436
+ figsize: tuple[float, float] | None = None,
437
+ ax: Axes | None = None,
438
+ config: str | Path | Config | None = None,
439
+ ) -> tuple[Figure, Axes]:
440
+ """Plot a Site × Indicator compliance dot matrix encoding Pass/Fail and Final/Interim.
441
+
442
+ Filled circles indicate Final results (``nOK == "OK"`` or ``interim_col == False``);
443
+ hollow ringed circles indicate Interim results (e.g., ``Insufficient data``).
444
+
445
+ Returns:
446
+ Tuple of ``(fig, ax)``.
447
+ """
448
+ cfg = ensure_config(config if config is not None else "horizons_one_plan")
449
+ resolved_site = resolve_column(site_col, cfg, "site_id")
450
+ if indicator_col is not None:
451
+ resolved_ind = indicator_col
452
+ elif "attribute_label" in cfg.columns and cfg.columns["attribute_label"] in df.columns:
453
+ resolved_ind = cfg.columns["attribute_label"]
454
+ else:
455
+ resolved_ind = resolve_column(None, cfg, "indicator")
456
+ resolved_res = resolve_column(result_col, cfg, "state_band")
457
+
458
+ validate_columns(
459
+ df, [resolved_site, resolved_ind, resolved_res], context="compliance_dot_matrix"
460
+ )
461
+
462
+ resolved_palette = (
463
+ dict(palette)
464
+ if palette is not None
465
+ else cfg.palettes.get(palette_key, resolve_palette(None, cfg, "state_bands"))
466
+ )
467
+ pass_color = resolved_palette.get("Pass", "#009ec2")
468
+ fail_color = resolved_palette.get("Fail", "#263742")
469
+
470
+ work = df.copy()
471
+ sites = (
472
+ list(site_order)
473
+ if site_order is not None
474
+ else sorted(work[resolved_site].dropna().astype(str).unique().tolist())
475
+ )
476
+ indicators = (
477
+ list(indicator_order)
478
+ if indicator_order is not None
479
+ else list(dict.fromkeys(work[resolved_ind].dropna().astype(str).tolist()))
480
+ )
481
+
482
+ site_to_y = {s: idx for idx, s in enumerate(sites)}
483
+ ind_to_x = {ind: idx for idx, ind in enumerate(indicators)}
484
+
485
+ ok_col = interim_col if interim_col is not None else cfg.columns.get("filter_ok")
486
+
487
+ has_interim_pass = False
488
+ has_interim_fail = False
489
+
490
+ with mpl_theme(cfg):
491
+ if ax is None:
492
+ fig_w = max(7.5, 0.85 * len(indicators) + 3.8)
493
+ fig_h = max(4.8, 0.55 * len(sites) + 2.8)
494
+ fig, ax = plt.subplots(figsize=figsize or (fig_w, fig_h))
495
+ else:
496
+ fig = ax.figure # type: ignore[assignment]
497
+
498
+ ax.set_facecolor(cfg.theme.background_color)
499
+
500
+ for _, row in work.iterrows():
501
+ s_val = str(row[resolved_site])
502
+ i_val = str(row[resolved_ind])
503
+ if s_val not in site_to_y or i_val not in ind_to_x:
504
+ continue
505
+
506
+ raw_res = row[resolved_res]
507
+ if pd.isna(raw_res):
508
+ continue
509
+ is_pass = (
510
+ bool(raw_res)
511
+ if isinstance(raw_res, (bool, np.bool_))
512
+ else str(raw_res).strip().lower() in {"pass", "true", "1"}
513
+ )
514
+
515
+ is_interim = False
516
+ if ok_col and ok_col in work.columns and pd.notna(row[ok_col]):
517
+ ok_val = row[ok_col]
518
+ if isinstance(ok_val, (bool, np.bool_)):
519
+ is_interim = bool(ok_val) if interim_col else not bool(ok_val)
520
+ else:
521
+ is_interim = str(ok_val).strip().upper() != "OK"
522
+
523
+ color = pass_color if is_pass else fail_color
524
+ if is_interim:
525
+ if is_pass:
526
+ has_interim_pass = True
527
+ else:
528
+ has_interim_fail = True
529
+ ax.scatter(
530
+ ind_to_x[i_val],
531
+ site_to_y[s_val],
532
+ s=marker_size,
533
+ facecolors=cfg.theme.background_color,
534
+ edgecolors=color,
535
+ linewidths=2.2,
536
+ zorder=4,
537
+ )
538
+ else:
539
+ ax.scatter(
540
+ ind_to_x[i_val],
541
+ site_to_y[s_val],
542
+ s=marker_size,
543
+ facecolors=color,
544
+ edgecolors=color,
545
+ linewidths=1.0,
546
+ zorder=4,
547
+ )
548
+
549
+ ax.set_xticks(range(len(indicators)))
550
+ ax.set_xticklabels(indicators, rotation=270, ha="center", va="top")
551
+ ax.set_yticks(range(len(sites)))
552
+ ax.set_yticklabels(sites)
553
+ ax.set_xlim(-0.7, len(indicators) - 0.3)
554
+ ax.set_ylim(-0.7, len(sites) - 0.3)
555
+ ax.tick_params(length=0, pad=8)
556
+ ax.grid(False)
557
+ for spine in ax.spines.values():
558
+ spine.set_visible(False)
559
+
560
+ if title:
561
+ ax.set_title(
562
+ title,
563
+ fontsize=cfg.theme.title_size,
564
+ fontweight=cfg.theme.title_weight,
565
+ color=cfg.theme.text_color,
566
+ pad=14,
567
+ )
568
+
569
+ handles = [
570
+ Line2D(
571
+ [0],
572
+ [0],
573
+ marker="o",
574
+ color="w",
575
+ label="Pass (Final)",
576
+ markerfacecolor=pass_color,
577
+ markeredgecolor=pass_color,
578
+ markersize=12,
579
+ ),
580
+ ]
581
+ if has_interim_pass:
582
+ handles.append(
583
+ Line2D(
584
+ [0],
585
+ [0],
586
+ marker="o",
587
+ color="w",
588
+ label="Pass (Interim)",
589
+ markerfacecolor=cfg.theme.background_color,
590
+ markeredgecolor=pass_color,
591
+ markeredgewidth=2.0,
592
+ markersize=12,
593
+ )
594
+ )
595
+ handles.append(
596
+ Line2D(
597
+ [0],
598
+ [0],
599
+ marker="o",
600
+ color="w",
601
+ label="Fail (Final)",
602
+ markerfacecolor=fail_color,
603
+ markeredgecolor=fail_color,
604
+ markersize=12,
605
+ )
606
+ )
607
+ if has_interim_fail:
608
+ handles.append(
609
+ Line2D(
610
+ [0],
611
+ [0],
612
+ marker="o",
613
+ color="w",
614
+ label="Fail (Interim)",
615
+ markerfacecolor=cfg.theme.background_color,
616
+ markeredgecolor=fail_color,
617
+ markeredgewidth=2.0,
618
+ markersize=12,
619
+ )
620
+ )
621
+
622
+ ax.legend(
623
+ handles=handles,
624
+ loc="upper left",
625
+ bbox_to_anchor=(-0.48, -0.08),
626
+ frameon=False,
627
+ fontsize=cfg.theme.legend_size,
628
+ labelspacing=0.9,
629
+ )
630
+
631
+ if caption:
632
+ fig.text(
633
+ 0.5,
634
+ 0.01,
635
+ caption,
636
+ ha="center",
637
+ va="bottom",
638
+ fontsize=cfg.theme.caption_size,
639
+ color=cfg.theme.caption_color,
640
+ )
641
+
642
+ return fig, ax