Skip to main content

pyControlCharts

Tests

A Python library for Statistical Process Control (SPC) charts (also known as control charts or Shewhart charts). Build machine-readable chart data with pandas; optionally plot interactively with Plotly.

XbarR control chart example XbarR chart with variation chart plotted.

Features

  • All major chart types. Variables (XmR, X-bar/R, X-bar/S) and attributes (p, np, c, u); one consistent API and output schema for all.
  • Run tests. Out-of-control detection (Nelson rules, configurable); violations include type codes and human-readable descriptions.
  • Multi-phase and spec limits. Per-phase control limits; specification limits as single value, list, or DataFrame column.
  • Variable subgroups. X-bar/R and X-bar/S support fixed or variable subgroup sizes.
  • Custom limits. Apply run tests to pre-computed limits (e.g. from a baseline).
  • Simple API. One call per chart; optional built-in plotting for all types.
  • Export. CSV, Excel, or JSON for pipelines, reports, or downstream tools.
  • Pandas integration. Every chart returns a single DataFrame with limits, violations, phases, and optional spec limits; same schema for all chart types.
  • Type-safe. Full type hints; Python 3.10+.
  • Well-tested. Test suite with validated examples from Wheeler's "Understanding Statistical Process Control".

Supported chart types

  • Variables (continuous data): XmR (Individuals and Moving Range), X-bar/R, X-bar/S.
  • Attributes (discrete/count data): p-chart, np-chart, c-chart, u-chart.

See User guide for details.

Why pycontrolcharts?

  • Machine-readable charts. Fixed schema for all chart types: limits, sigma lines, violations, phases, spec limits. Export to CSV, Excel, or JSON and plug into pipelines, tools, LLM or AI agents.
  • Optional Plotly. When you need a chart, use built-in plotting for any chart type. Interactive HTML, multi-phase limits, violation markers.
  • Few dependencies. Core install is pandas only. Add the plotly extra only if you want built-in plotting.
  • Easy to integrate with AI. Structured DataFrame and JSON export with clear violation types and descriptions. Fits naturally into agent workflows and tool use.
  • Industry-aligned. Nelson run tests by default; configurable (e.g. Western Electric). Formulas and constants from Wheeler and Montgomery.
  • Validated. Test suite aligned with Wheeler's "Understanding Statistical Process Control"; same limits and behaviour you can verify from the book.

Installation

pip install pycontrolcharts

For Plotly plotting:

pip install pycontrolcharts[plotly]

Quick start

1. Compute chart data (no plotting)

from pycontrolcharts import calc_xmr

data = [39, 41, 41, 41, 43, 44, 41, 42, 40, 41, 44, 40]
df = calc_xmr(data)

print(f"Center line: {df['center_line'].iloc[0]:.2f}, UCL: {df['ucl'].iloc[0]:.2f}")
violations = df[df['violations'].apply(len) > 0]
print(f"Out-of-control points: {len(violations)}")

Example output (subset of columns only; see API reference for full schema):

   point_id  value  center_line     ucl     lcl violations ...
0         0     39         41.5  44.16  38.84         []
1         1     41         41.5  44.16  38.84         []
2         2     41         41.5  44.16  38.84         []

2. Plot with Plotly (optional)

from pycontrolcharts import calc_xmr, plot_control_chart, ChartType

df = calc_xmr([39, 41, 41, 41, 43, 44])
fig = plot_control_chart(df, ChartType.XMR, title="Pressure")
fig.show()
# or: fig.write_html("xmr.html")

3. Export chart to JSON

The chart DataFrame can be exported to JSON for pipelines, APIs, or AI tools:

from pycontrolcharts import calc_xmr

df = calc_xmr([39, 41, 41, 41, 43, 44])
df.to_json("chart.json", orient="records", indent=2, date_format="iso")
# Or get a string: json_str = df.to_json(orient="records")

Example output (excerpt of chart.json):

[
  {
    "point_id": 0,
    "value": 39,
    "label": 1,
    "center_line": 41.5,
    "ucl": 44.16,
    "lcl": 38.84,
    "spec_upper": null,
    "spec_lower": null,
    "phase": null,
    "violations": [],
    "variation": null,
    "variation_ucl": 3.268,
    "variation_cl": 1.0,
    "variation_lcl": 0.0,
    "variation_violations": []
  },
  {
    "point_id": 1,
    "value": 41,
    "label": 2,
    "center_line": 41.5,
    "ucl": 44.16,
    "lcl": 38.84,
    "violations": [],
    "variation": 2.0,
    ...
  }
]

Each row in the JSON is one point (e.g. one measurement for XmR). See API reference for the full output schema.

Documentation

License

MIT. Author: Antti Suanto.

Metadata

Release files for pycontrolcharts 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pycontrolcharts 0.1.2
File Size Uploaded
pycontrolcharts-0.1.2.tar.gz 407.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pycontrolcharts 0.1.2
File Interpreter ABI Platform
pycontrolcharts-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 452.4 kB

Release files / pycontrolcharts-0.1.2.tar.gz

Download URL pycontrolcharts-0.1.2.tar.gz
Size 407.8 kB
Tags Source
SHA-256 checksum
How to use checksums
be923c2a2323ef3be87a04b7c220d8a474185d944bac5fb025ebef7bd24b3d2d
BLAKE2b-256 checksum
How to use checksums
a55cbd36f5b8335d6aa416477e350d0638feccdd2f6e3c47009cb875cb70603e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 6, 2026.

Transparency log

Release files / pycontrolcharts-0.1.2-py3-none-any.whl

Download URL pycontrolcharts-0.1.2-py3-none-any.whl
Size 44.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1ed8dfacfa7877dadc0d1ef3e510cceb510c03c85966f45689f08ed11ac58d23
BLAKE2b-256 checksum
How to use checksums
a6af6f7660cfed1cb740ddf5e6ca8ff273d0561e5760d148dc533b88d5049b04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 6, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page