Visualization¶
HypoTestX provides several helpers for plotting test results and distributions. All visualization functions require matplotlib (and some support the optional plotly backend):
pip install matplotlib
# or, for matplotlib + plotly together:
pip install hypotestx[visualization]
result.plot()¶
Every HypoResult has a .plot() method that auto-selects the best chart type
for the test:
import hypotestx as hx
result = hx.ttest_2samp(group1, group2)
fig = result.plot() # auto
fig = result.plot(kind="bar") # grouped bar with CI
fig = result.plot(kind="box") # box plot
fig = result.plot(kind="p_value") # p-value on null distribution
fig.savefig("result.png")
|
Description |
|---|---|
|
Best chart type for the test (default) |
|
Mean ± 95 % CI bar chart for two-group tests |
|
Box plots of group distributions |
|
Test statistic highlighted on the null distribution |
plot_result()¶
Standalone function — equivalent to result.plot():
from hypotestx.explore.visualize import plot_result
# or via public API (if exposed in __init__.py)
import hypotestx as hx
fig = hx.plot_result(result, kind="auto")
fig.show()
plot_distributions()¶
Plot the raw distributions of one or more groups:
import hypotestx as hx
fig = hx.plot_distributions(
[group1, group2],
labels=["Control", "Treatment"],
kind="box", # "box" (default) | "bar" | "violin"
title="Group Comparison",
)
fig.show()
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
— |
Data for each group |
|
|
|
Group labels |
|
|
|
Chart type: |
|
|
|
Plot title |
plot_p_value()¶
Visualise a p-value on the null distribution for a given test statistic:
import hypotestx as hx
fig = hx.plot_p_value(
p_value=0.023,
alpha=0.05,
test_statistic=2.41,
alternative="two-sided",
)
fig.show()
The rejection region is highlighted in red; the critical value lines and the test statistic are annotated.
generate_report()¶
Generate a formatted report — HTML, PDF, or plain text:
import hypotestx as hx
result = hx.ttest_2samp(group1, group2)
# Return as string
html = hx.generate_report(result, fmt="html")
text = hx.generate_report(result, fmt="text")
# Write to file
hx.generate_report(result, path="report.html", fmt="html")
hx.generate_report(result, path="report.pdf", fmt="pdf") # requires weasyprint
hx.generate_report(result, path="report.txt", fmt="text")
|
Description |
Extra requirement |
|---|---|---|
|
HTML with embedded chart (if matplotlib is installed) |
None |
|
PDF via WeasyPrint |
|
|
Plain text summary |
None |
Reporting module helpers¶
For lower-level control:
from hypotestx.reporting.generator import export_html, export_pdf, export_csv
# Single result to HTML file
export_html(result, path="report.html")
# PDF (requires weasyprint)
export_pdf(result, path="report.pdf")
# Multiple results to CSV
export_csv([result1, result2, result3], path="results.csv")
Notes¶
All
plot_*functions return amatplotlib.figure.Figureobject. Call.show()to display interactively or.savefig(path)to write to disk.If matplotlib is not installed, these functions raise an
ImportErrorwith a helpful install message.plot_effect_size(),plot_assumptions(), andgenerate_apa_report()from older documentation are not yet implemented. Useresult.plot(),plot_distributions(), andapa_report()respectively.