A Python package for creating perceptually uniform colormaps based on biological cell type similarity
Project description
ColorMyCells
A Biological Approach to Cell Type Visualization
colormycells is a Python package that solves a common problem in single-cell analysis: creating colormaps where the perceptual distance between colors meaningfully represents the biological similarity between cell types.
The Problem: Color Selection in Single-Cell Visualization
Standard colormaps like tab10 or rainbow aren't great when applied to single-cell data:
- Biological meaning is lost: Default colormaps assign colors arbitrarily, with no relation to cell type similarity
- Perceptual imbalance: Some colors jump out while others blend together, drawing attention to cell types for no biological reason
- Limited palette: Most standard colormaps support 10-20 colors, but you may have hundreds of cell types
| Standard Colormap | ColorMyCells |
Installation
pip install colormycells
For 3D visualization support (optional):
pip install colormycells[full]
Dependencies
- numpy
- pandas
- matplotlib
- seaborn
- scikit-learn
- scipy
- colour-science
Optional Dependencies (for 3D visualization)
- pillow
- ipython
Usage
import scanpy as sc
from colormycells import get_colormap
# Load your data
adata = sc.read_h5ad("your_data.h5ad")
# Create a colormap based on cell type similarities
colors = get_colormap(adata, key="cell_type")
# Use the colormap for plotting
sc.pl.umap(adata, color="cell_type", palette=colors)
# Visualize the color space with 2D and 3D plots
colors = get_colormap(adata, key="cell_type", plot_colorspace=True)
# A 2D scatter plot will be displayed, and in Jupyter notebooks
# an interactive 3D rotating visualization will also be shown
# Create reproducible colormap with seed
colors1 = get_colormap(adata, key="cell_type", seed=123)
colors2 = get_colormap(adata, key="cell_type", seed=123) # colors1 and colors2 will be identical
You can also pass a file path directly:
# Load directly from file
colors = get_colormap("your_data.h5ad", key="cell_type")
# Works with various file formats
colors = get_colormap("expression_matrix.csv", key="cell_type")
Parameters
- adata: AnnData object with observations/cells as rows and variables/genes as columns
- key: Key in adata.obs encoding cell type information (default: "cell_type")
- plot_colorspace: Whether to visualize the colorspace (default: False)
- include_unknown: Whether to include "Unknown" category in the colormap (default: False)
- unknown_color: Color to use for "Unknown" category if not included (default: 'w')
- deficiency: Type of color vision deficiency to simulate (options: None, "Deuteranomaly", "Protanomaly", "Tritanomaly", default: None)
- severity: Severity of color vision deficiency (0-100, default: 0)
- seed: Random seed for reproducible colormaps (default: 42, set to None for stochastic behavior)
Our Approach: Biology-Driven Color Assignment
colormycells takes a fundamentally different approach:
- Biological similarity drives color selection: Similar cell types receive similar colors
- Gene expression determines color: We use the average expression profile of each cell type (pseudobulk) to measure cell type similarity
- Perceptually uniform color space: We map cell type relationships to the LUV color space, where perceptual distances are uniform
- Intuitive visualization: The result is a colormap where visual intuition aligns with biological reality
The result is a colormap where:
- Similar cell types appear in similar colors
- Color distances reflect biological relationships
- Visualizations become more intuitive to interpret
Note
Color vision deficiency simulation is currently not fully implemented.
License
GPL-3.0 License
How to Cite
If you use ColorMyCells in your research, please cite:
Ari Benjamin. (2025). ColorMyCells: A Python package for biologically faithful colormaps for cell type visualization. (Version 0.1.0). Zenodo. https://doi.org/10.5281/zenodo.15595324
or the bibtex entry:
@software{colormycells2025,
author = {Benjamin, Ari},
title = {{ColorMyCells: A Python package for biologically
faithful colormaps for cell type visualization}},
month = jun,
year = 2025,
publisher = {Zenodo},
version = {0.1.0},
doi = {10.5281/zenodo.15595324},
url = {https://doi.org/10.5281/zenodo.15595324},
note = {Available at: https://github.com/ZadorLaboratory/colormycells}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file colormycells-0.1.3.tar.gz.
File metadata
- Download URL: colormycells-0.1.3.tar.gz
- Upload date:
- Size: 23.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2c40c4afa1c1a1c406ef044af9c60462211d68722281391b3605e9fdf066637
|
|
| MD5 |
8409f7779761a9cd6af46eeee6a3623c
|
|
| BLAKE2b-256 |
c0cb14e00582683ed31eb26006cba4e37d47b431297f9b857ff8f513f1145b69
|
File details
Details for the file colormycells-0.1.3-py3-none-any.whl.
File metadata
- Download URL: colormycells-0.1.3-py3-none-any.whl
- Upload date:
- Size: 21.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4e4c719654c612637e4a35732b7eca6edcfae83f3bde99c3830b2a934cf695b
|
|
| MD5 |
4b1f664570d7044486235d0547f67dfd
|
|
| BLAKE2b-256 |
3fc508858910537877f8e5fae2ab89a61c02d6aee3a63d3dc55e2fa98ef6f5d5
|