Skip to main content

opticquiz-cvd (Python)

PyPI version PyPI downloads DOI

Is your chart colorblind-safe? Red-green color-vision deficiency affects ~1 in 12 men — and the classic failure is a plot where the red series and the green series look identical to those readers. This checks any palette for that, fixes it if it fails, and also checks WCAG contrast — with zero dependencies, dropping straight into a matplotlib / plotly / seaborn workflow.

It simulates protanopia, deuteranopia and tritanopia (Machado 2009, or Brettel 1997) and scores perceptual difference with CIEDE2000, flagging pairs that are distinct to normal vision but collapse under a color-vision-deficiency simulation.

Method (citable): https://doi.org/10.5281/zenodo.21310578

Install

pip install opticquiz-cvd

Check a chart palette

import opticquiz_cvd as cvd

report = cvd.check_palette(["#d7191c", "#1a9641", "#2166ac"])
report["pass"]                         # False
report["types"]["deutan"]["conflicts"]
# [{'a': '#d7191c', 'b': '#1a9641', 'normal': 70.6, 'sim': 8.1, 'severity': 'risk'}]

Works directly with matplotlib colors (hex, or 0-1 / 0-255 RGB tuples):

import matplotlib.pyplot as plt, opticquiz_cvd as cvd
cycle = plt.rcParams["axes.prop_cycle"].by_key()["color"]
print("colorblind-safe:", cvd.check_palette(cycle)["pass"])

check_palette(colors, distinct=13, collapse=10, severity=1.0, model="machado")severity (0–1) checks milder anomalous trichromacy; model is "machado" or "brettel".

Fix a failing palette

fixed = cvd.fix_palette(["#d7191c", "#1a9641"])
fixed["colors"]   # ['#c80011', '#2da24c']  — now colorblind-safe
fixed["drift"]    # [4.0, 4.1]  — how far each color moved (CIEDE2000)
fixed["pass"]     # True

Check contrast (WCAG)

cvd.check_contrast("#767676", "#ffffff")
# {'ratio': 4.54, 'AA': True, 'AAA': False, 'ui': True, 'pass': True}
cvd.contrast_ratio("#000000", "#ffffff")   # 21.0

Simulate

cvd.simulate("#d7191c", "deutan")               # '#8a7b0c'  (Machado, full)
cvd.simulate("#d7191c", "deutan", 0.5)          # milder
cvd.simulate("#d7191c", "deutan", 1.0, "brettel")
cvd.delta_e("#d7191c", "#1a9641")               # 70.6

Command line

python -m opticquiz_cvd "#d7191c" "#1a9641" "#2166ac"
# FAIL - color conflicts found (3 colors)
#   deutan: #d7191c/#1a9641 dE8.1(risk)

Honest scope

Simulates a model of color vision — an approximation of a diverse population, not any single person's vision — and results depend on an uncalibrated screen. Severity below 1 is a disclosed approximation of anomalous trichromacy. It is not a legal accessibility audit and does not certify ADA / Section 508 / WCAG / EU Accessibility Act compliance.

License

MIT. Methods: Machado, Oliveira & Fernandes (2009); Brettel, Viénot & Mollon (1997); CIEDE2000; WCAG 2.x. Part of OpticQuiz.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opticquiz_cvd-1.1.1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opticquiz_cvd-1.1.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file opticquiz_cvd-1.1.1.tar.gz.

File metadata

  • Download URL: opticquiz_cvd-1.1.1.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for opticquiz_cvd-1.1.1.tar.gz
Algorithm Hash digest
SHA256 327b7707c0e9229aab427471b58ba7cded1e3c8845cdee23a0756e88d61261c1
MD5 1906d0d86c75d6c7d6b605d01245f3b3
BLAKE2b-256 30fcef6cae29fae90a22feafd904632027071fb25153c6527d47de68d9786fe0

See more details on using hashes here.

File details

Details for the file opticquiz_cvd-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: opticquiz_cvd-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for opticquiz_cvd-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ac1744bc360aa1b1f32da4aa15805a8755eafb31b0ff9e9d52063af00eaecec5
MD5 e8eae5f79ac5923881861d503edf9c9c
BLAKE2b-256 d32453f9a7fcda55c0a0e4d155c53726b25fb34915b6874da3e4f4dc77aa9672

See more details on using hashes here.

Release history Release notifications | RSS feed

1.1.3

2 files

1.1.2

2 files

This release

1.1.1 This release

2 files

1.1.0

2 files

1.0.0

2 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