Realcolor
Simulate colorblindness in Python charts
Install / Use
/learn @y-sunflower/RealcolorREADME
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).
<br>[!NOTE] Colorblindness affects up to 1 in 12 males (8%) and 1 in 200 females (0.5%)[^1]
Installation
pip install realcolor
<br>
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)

<br>[!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")}
<br>
Contributing
-
Fork the repository to your own GitHub account.
-
Clone your forked repository to your local machine (ensure you have Git installed):
git clone https://github.com/YOUR_NAME/realcolor.git
cd realcolor
- Create a new branch:
git checkout -b my-feature
- Set up your Python environment (ensure you have uv installed):
uv sync --all-extras --dev
uv run pre-commit install
uv pip install -e .
- Test that everything works correctly by running:
uv run pytest
<br>
[^1]: Deane B. Judd, "Facts of Color-Blindness*," J. Opt. Soc. Am. 33, 294-307 (1943)
