Colormap 2D Python Package
This package allows to map 2D coordinates to different 2D color maps.
The following color maps are available:
| ColorMap2DBremm | ColorMap2DCubeDiagonal | ColorMap2DSchumann |
| ColorMap2DSteiger | ColorMap2DTeuling2 | ColorMap2DZiegler |
The package is based on
M. Steiger, J. Bernard, S. Thum, S. Mittelstädt, M. Hutter, D. A. Keim, and J. Kohlhammer, “Explorative Analysis of 2D Color Maps,” in International Conferences in Central Europe on Computer Graphics, Visualization and Computer Vision, 2015, vol. 23, pp. 151–160.
For a JavaScript implementation, refer to the Color2D project by Dominik Jäckle.
Installation
Install the package from PyPI:
pip install pycolormap-2d
The package needs Python 3.9 or newer. Its only dependency is NumPy.
Usage
Basic usage with normalized inputs (i.e., x- and y-coordinates ranging from 0 to 1):
from pycolormap_2d import ColorMap2DBremm
# Create the color map object.
cmap = ColorMap2DBremm()
# Get the color value.
color = cmap(0.2, 0.6) # array([181, 116, 75], dtype=uint8)
The color is a NumPy array with the red, green, and blue values as integers from 0 to 255.
Optionally, ranges for the input x and y input ranges can be passed during object creation:
from pycolormap_2d import ColorMap2DBremm
# Create the color map object.
cmap = ColorMap2DBremm(range_x=(-10, 30), range_y=(1, 11))
# Get the color value.
color = cmap(10.0, 8.5)
Values outside the range are clamped to the nearest edge of the color map. For example, cmap(-50, 8.5) returns the same color as cmap(-10, 8.5).
All six color maps share the same interface. Swap ColorMap2DBremm for any other class from the table above:
from pycolormap_2d import ColorMap2DZiegler
cmap = ColorMap2DZiegler()
color = cmap(0.2, 0.6)
To get the full color map as an image, use get_cmap_data(). It returns a NumPy array of shape (512, 512, 3):
from pycolormap_2d import ColorMap2DBremm
data = ColorMap2DBremm().get_cmap_data()
Example: coloring a scatter plot
A common use is to color the points of a 2D embedding (e.g., from PCA, t-SNE, or UMAP) by their position. This example uses Matplotlib, which you need to install separately:
import matplotlib.pyplot as plt
import numpy as np
from pycolormap_2d import ColorMap2DBremm
points = np.random.default_rng(0).normal(size=(500, 2))
# Fit the color map to the extent of the data. The ranges must contain
# Python numbers, so convert the NumPy values with float().
cmap = ColorMap2DBremm(
range_x=(float(points[:, 0].min()), float(points[:, 0].max())),
range_y=(float(points[:, 1].min()), float(points[:, 1].max())),
)
# Matplotlib expects RGB values from 0 to 1.
colors = np.array([cmap(x, y) for x, y in points]) / 255
plt.scatter(points[:, 0], points[:, 1], c=colors)
plt.show()
Development
Set up a development environment with Pipenv and run the checks:
pipenv sync --dev
pipenv run pip install -e .
pipenv run pytest tests/
pipenv run flake8 pycolormap_2d tests
pipenv run mypy pycolormap_2d
The Pipfile pins the development environment to the newest supported Python version, which must be installed.
To run the tests on all supported Python versions, use tox. It needs each of these Python versions installed:
tox
Metadata
Release files for pycolormap-2d 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pycolormap_2d-1.2.0.tar.gz | 1.4 MB | Without provenance | Details for pycolormap_2d-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pycolormap_2d-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for pycolormap_2d-1.2.0-py3-none-any.whl |
Total release size: 2.7 MB
Release files / pycolormap_2d-1.2.0.tar.gz
| Download URL | pycolormap_2d-1.2.0.tar.gz |
|---|---|
| Size | 1.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
56477ec8952e0c97be9abeffc453bfea6210d86ffc3716ffedb1b1ad8018505a
|
|
BLAKE2b-256 checksum How to use checksums |
fbb2eff470700d2a6911e91a6dc51d3df0878417aaf41326634ff198ece69438
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / pycolormap_2d-1.2.0-py3-none-any.whl
| Download URL | pycolormap_2d-1.2.0-py3-none-any.whl |
|---|---|
| Size | 1.3 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
82ecf39032fb73eac1d7bd06cda1adb49853cc962ba6a224fd717a950e4f075a
|
|
BLAKE2b-256 checksum How to use checksums |
e776d79641bde7a5cf71fc08005d6f9769162a233c0c246f0e6fe1fb469ce077
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for pycolormap-2d 1.2.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.