Skip to main content

Simulate colorblindness in Python charts

Project description

realcolor: simulate colorblindness in Python charts

realcolor is a lightweight Python package designed to show how colorblind people see your graphs. It simulates all types of colorblindness (deuteranopia, protanopia, tritanopia) by showing you your graphic as seen by a colorblind person. It works with matplotlib and everything built on top of it (seaborn, plotnine, etc).

[!NOTE] Colorblindness affects up to 1 in 12 males (8%) and 1 in 200 females (0.5%)[^1]


Installation

pip install realcolor

Quick start

  • Matplotlib
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot([1, 2, 3], [4, 2, 5], label="Group A", lw=4)
ax.plot([1, 2, 3], [2, 5, 3], label="Group B", lw=4)
ax.legend()

from realcolor import simulate_colorblindness

simulate_colorblindness(fig)

  • Plotnine
from plotnine import ggplot, geom_point, aes
from plotnine.data import anscombe_quartet
from realcolor import simulate_colorblindness

ggp = ggplot(anscombe_quartet, aes(x="x", y="y", color="dataset")) + geom_point(size=10)
simulate_colorblindness(ggp)

[!TIP] Looking for support of other data visualization libraries? Open an issue.


Other features

  • Simulate just one kind of colorblindness (one of "deuteranopia", "protanopia", "tritanopia", "desaturated"):
simulate_colorblindness(fig, kind="protanopia")

  • Control the severity of the simulation (between 0 to 100, default to 100):
simulate_colorblindness(fig, kind="protanopia", severity=50)

  • Score how colorblind-friendly a set of colors is (0 = indistinguishable, 100 = perfectly distinguishable):
from realcolor import colorblind_score

score = colorblind_score(["red", "green", "blue"])

score.overall
#> 52.1

score.deuteranopia
#> {"score": 66.7, "min_deltaE": 16.7, "worst_pair": ("#ff0000", "#008000")}

[^1]: Deane B. Judd, "Facts of Color-Blindness*," J. Opt. Soc. Am. 33, 294-307 (1943)

Project details


Download files

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

Source Distribution

realcolor-0.2.0.tar.gz (419.7 kB view details)

Uploaded Source

Built Distribution

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

realcolor-0.2.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file realcolor-0.2.0.tar.gz.

File metadata

  • Download URL: realcolor-0.2.0.tar.gz
  • Upload date:
  • Size: 419.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for realcolor-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ddfb8e29a79361bf86d8a84b4bf613aa43f897050776242e3aa6875741818aa3
MD5 73782cd43701194eb80f56839bef5871
BLAKE2b-256 5a32810b6584e938785e5e08aa0e4486cf78773d174d5b9e640a0eaddf72f32a

See more details on using hashes here.

Provenance

The following attestation bundles were made for realcolor-0.2.0.tar.gz:

Publisher: pypi.yaml on y-sunflower/realcolor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file realcolor-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: realcolor-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for realcolor-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 16b63c44c86a2d2773fb2dd6b31c924bed2bb8aad1f293ea6551dbe5e45b44c8
MD5 7e67f7d0e9c6c0a640ff5c9b7a52f8f4
BLAKE2b-256 34a0f5b2ab95a97ebd4c7170cde0f834fa06920d5ae72a2972f834ffec66d421

See more details on using hashes here.

Provenance

The following attestation bundles were made for realcolor-0.2.0-py3-none-any.whl:

Publisher: pypi.yaml on y-sunflower/realcolor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page