Visualization

All visualization functions require matplotlib (install with pip install hypotestx[visualization]).

hypotestx.explore.visualize.plot_result(result: Any, kind: str = 'auto') Any[source]

Generate a figure summarising a HypoResult.

Automatically picks the best chart type based on the test: - "p_value" - p-value distribution curve - "bar" - bar chart (when group means are in data_summary) - "auto" - pick automatically

Parameters:
  • result (HypoResult)

  • kind (str) – "auto", "p_value", "bar", "box".

Return type:

matplotlib.figure.Figure

hypotestx.explore.visualize.plot_distributions(groups: List[Sequence[float]], labels: List[str] | None = None, title: str = '', kind: str = 'box') Any[source]

Plot the distribution of one or more groups side-by-side.

Parameters:
  • groups (list of sequences) – Each element is a numeric sequence (one per group).

  • labels (list of str, optional) – Group labels. Defaults to ["Group 1", "Group 2", ...].

  • title (str) – Plot title.

  • kind (str) – "box" (default), "violin", or "bar".

Return type:

matplotlib.figure.Figure

hypotestx.explore.visualize.plot_p_value(p_value: float, alpha: float = 0.05, degrees_of_freedom: float | None = None, test_statistic: float | None = None, alternative: str = 'two-sided', title: str = '') Any[source]

Visualise the p-value on a standard-normal (or t) distribution curve.

Hatches the rejection region(s) and marks the observed p-value.

Parameters:
  • p_value (float)

  • alpha (float) – Significance level (default 0.05).

  • degrees_of_freedom (float, optional) – If provided, a t-distribution tail is shown instead of normal.

  • test_statistic (float, optional) – If provided, marks the observed statistic on the x-axis.

  • alternative (str) – "two-sided", "greater", or "less".

  • title (str) – Plot title.

Return type:

matplotlib.figure.Figure

Reporting Functions

hypotestx.reporting.generator.text_report(result: HypoResult, verbose: bool = True) str[source]

Generate a detailed plain-text report for a single HypoResult.

Parameters:
  • result (HypoResult)

  • verbose (include sample sizes, assumptions, data summary (default True))

Returns:

str

Return type:

multi-line report

hypotestx.reporting.generator.export_html(result: HypoResult, path: str | None = None) str[source]

Generate a self-contained HTML report for a single HypoResult.

Delegates to hypotestx.explore.visualize.generate_report() so that an embedded plot is included when matplotlib is installed.

Parameters:
  • result (HypoResult)

  • path (optional output file path (e.g. "report.html").) – If None, the HTML string is returned without saving.

Returns:

str

Return type:

HTML content

hypotestx.reporting.generator.export_pdf(result: HypoResult, path: str) None[source]

Save a PDF report for a single HypoResult.

Requires weasyprint:

pip install weasyprint
Parameters:
  • result (HypoResult)

  • path (output file path (e.g. "report.pdf").)

hypotestx.reporting.generator.export_csv(results: List[HypoResult], path: str, sep: str = ',') None[source]

Write a batch of HypoResult objects to a CSV file.

Parameters:
  • results (list of HypoResult)

  • path (output file path)

  • sep (delimiter (default ','))

hypotestx.reporting.generator.apa_report(result: HypoResult) str[source]

Generate an APA-style results paragraph for a single HypoResult.

Parameters:

result (HypoResult from any test function)

Returns:

str

Return type:

APA-style citation suitable for use in a Results section

Example

An independent-samples t-test revealed a significant difference between groups, t(28) = 3.45, p = .001, d = 0.62 (medium).

Usage Examples

import hypotestx as hx

result = hx.ttest_2samp(group1, group2)

# Plot the result
fig = result.plot()                       # auto
fig = hx.plot_result(result, kind="bar")  # bar chart

# Plot distributions
fig = hx.plot_distributions(
    [group1, group2],
    labels=["Control", "Treatment"],
    kind="box",
)

# p-value visualization
fig = hx.plot_p_value(
    p_value=result.p_value,
    alpha=result.alpha,
    test_statistic=result.statistic,
    alternative=result.alternative,
)

# Reports
hx.generate_report(result, path="report.html", fmt="html")
hx.generate_report(result, path="report.pdf",  fmt="pdf")   # needs weasyprint