[NO-ISSUE] feat: Adding the plot function for experiment analysis - #267
Open
gae-ric wants to merge 1 commit into
Open
[NO-ISSUE] feat: Adding the plot function for experiment analysis#267gae-ric wants to merge 1 commit into
gae-ric wants to merge 1 commit into
Conversation
david26694
reviewed
May 21, 2026
| @@ -0,0 +1,3 @@ | |||
| # `from cluster_experiments.plotting import *` | |||
Owner
There was a problem hiding this comment.
try a make docs-serve ti check if it works
david26694
reviewed
May 21, 2026
| `cluster-experiments`. Install it on demand: | ||
|
|
||
| ```bash | ||
| pip install matplotlib |
Owner
There was a problem hiding this comment.
let's try to do something like
pip install cluster-experiments[matplotlib]
or some changes in the pyproject to make this work directly from a simple command in the installation of the library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
plot_experiment_results— scoreboard-style plotting for experiment resultsSummary
Adds a minimal, dependency-light plotting utility (
plot_experiment_results) forAnalysisPlanResults. It generalizes the prior single-treatment relative-onlyhelper to support both relative and absolute lift, both A/B and
A/B/n designs, and stacks one card per treatment-vs-control comparison in a
single figure.
matplotlibremains an optional dependency: imported lazily inside thefunction, with a clear
ImportErrorwhen missing.Motivation
Experiment readouts in this library currently stop at the
AnalysisPlanResultstable. Users have to roll their own plots every time. This PR closes that gap
with a single function that:
AnalysisPlanResultsdirectly (no adapter layer),infinite lift) without crashing.
What's included
Implementation
cluster_experiments/plotting.py— new module exposingplot_experiment_results(result, metric_type="relative", title=None, ax=None).colored lift indicator (▲ green / ▼ red / ● gray), centered CI bar with
-r% / 0% / +r%ticks.matplotlib.pyplotimport inside the function. No global import.seaborn,plotly, or pandas plotting wrappers introduced.Axesobject for further customization.cluster_experiments/__init__.py— re-exportsplot_experiment_resultsand adds it to
__all__.Tests
tests/test_plotting.py— 16 pytest cases covering:+inf/-inflabel +xmarker; NaN values;missing CI bounds; missing p-values; negative-significant; positive-significant;
non-significant.
matplotlibmissing raises the documentedImportError.metric_typeraisesValueError.AnalysisPlanResultsraisesValueError.ax=parameter is honored.Agg; autouse fixture closes all figures between tests.Example outputs
examples/plotting_outputs/generate_plots.py— reproducible script thatwrites 16 PNGs covering every scenario above.
examples/plotting_outputs/*.png— 16 generated examples:2/3/4/5-variant, relative & absolute, all-significant, none-significant,
mixed signs, zero control mean (infinite lift), NaN values, missing CI,
missing p-values, large effects, custom
axwith stacked subplots, strictalpha.
Regenerate any time with:
Documentation
docs/plotting.md— full tutorial in the project's existingquickstart.mdstyle: installation note, numbered sections, mental-modeltable,
relativevsabsolutetable, multi-variant, filtering results,dimension slicing, scorecard layout, headless save, edge-case table,
embedded API reference via
mkdocstrings, and "Next Steps".docs/api/plotting.md— API stub matching the existingdocs/api/*.mdconvention (::: cluster_experiments.plotting).mkdocs.yml— registers the tutorial underExamples → Basic Usage → Plotting Experiment Results and the API reference
under API Reference → Experiment Analysis → Plotting.
Public API
Signature:
Design decisions
reads well as a stakeholder readout. Multi-variant simply stacks cards.
custom themes or abstractions.
matplotlibimport. Keeps the core package dependency-light;raises
"Plotting requires matplotlib. Install with: pip install matplotlib"if missing.
AnalysisPlanResultsattributes directly. No adapter, no DataFrameconversion required. Users filter the result themselves (a helper is shown
in
docs/plotting.md) when they want a single chart out of many rows.±inflabel +xmarker.NaN →
nanlabel +xmarker. Missing p-value → gray. Missing CI → no bar.Backwards compatibility
Purely additive:
cluster_experiments.plotting.plot_experiment_resultsincluster_experiments.__init__.matplotlib(already indev/docsextras; notpromoted to a core dependency).
No existing module, class, or function is modified.
Verification
Files
cluster_experiments/plotting.pycluster_experiments/__init__.pytests/test_plotting.pyexamples/plotting_outputs/generate_plots.pyexamples/plotting_outputs/*.png(16 files)docs/plotting.mddocs/api/plotting.mdmkdocs.ymlHow to review
cluster_experiments/plotting.py(~340 lines, one public function +small helpers).
examples/plotting_outputs/and flip through the 16 PNGs to verifythe visual output across edge cases.
docs/plotting.mdend-to-end — it doubles as the design walkthrough.Out of scope (deliberate)
AnalysisPlanResultsobjects — duck-typed viagetattrwith sensible defaults; explicit converter can come later if needed.
matplotlibto a core dependency — left optional per the brief.