Skip to main content

Scientific colormaps for python, without dependencies

Project description

cmap

License PyPI Conda Python Version CI codecov Documentation Status

Scientific colormaps for python, with no dependencies beyond numpy.

With cmap, you can use any of the colormaps from matplotlib, cmocean, colorbrewer, crameri, seaborn, and a host of other collections in your python code, without having to install matplotlib or any other dependencies beyond numpy.

:book: See the complete catalog

There are a number of python libraries that provide or require colormaps or basic color support, but they all either depend on matplotlib, provide a specialized set of colormaps intended to extend those provided by matplotlib, or roll their own colormap solution that vendors/duplicates other libraries.

cmap is a lightweight library that provides a large collection of colormaps with no dependencies beyond numpy. It provides exports to a number of known third-party colormap objects, allowing it to be used across a wide range of python visualization libraries. The intention is to provide a library that can be used by any python library that needs colormaps, without forcing the user to install matplotlib (while still being compatible with matplotlib and other libraries that use matplotlib colormaps).

cmap is strictly typed and fully tested, with a focus on good developer experience.

Install

pip install cmap
conda install -c conda-forge cmap

Usage

See Documentation for full details.

cmap.Color

The cmap.Color object is a simple wrapper around a tuple of RGBA scalars, with a few convenience methods for converting to other color objects.

from cmap import Color

red = Color("red")  # or a variety of other "color like" inputs

cmap.Colormap

The cmap.Colormap object is a callable that can map a scalar value (or numpy array of values) to an RGBA color (or a numpy array of RGBA colors). API is intended to mimic the behavior of a matplotlib.colors.Colormap object (without requiring matplotlib)

In [1]: import cmap

# or a variety of other "colormap like" inputs
In [2]: cmap1 = cmap.Colormap(["red", "green", "blue"])

In [3]: cmap1(np.linspace(0,1,5))
Out[3]:
array([[1.        , 0.        , 0.        , 1.        ],
       [0.50393701, 0.24900417, 0.        , 1.        ],
       [0.        , 0.50196078, 0.        , 1.        ],
       [0.        , 0.24900417, 0.50393701, 1.        ],
       [0.        , 0.        , 1.        , 1.        ]])

Note that the input array must be normalized from 0-1, so if you're applying a colormap to an integer array (like an image) you must apply any contrast limits and rescale to 0-1 before passing it to a Colormap.

Third Party Library Support

The cmap.Colormap object has convenience methods that export it to a number of known third-party colormap objects, including:

See documentation for details.

If you would like to see support added for a particular library, please open an issue or PR.

Alternatives

Other libraries providing colormaps:

References and Further reading

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

cmap-0.7.2.tar.gz (949.0 kB view details)

Uploaded Source

Built Distribution

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

cmap-0.7.2-py3-none-any.whl (995.9 kB view details)

Uploaded Python 3

File details

Details for the file cmap-0.7.2.tar.gz.

File metadata

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

File hashes

Hashes for cmap-0.7.2.tar.gz
Algorithm Hash digest
SHA256 9501cec4d5c2b7a821479aec3282b3d8b42fda983bad055e0f9dbc19cf7bc5b1
MD5 3147be9a7342a519e9e18fea7ea99ff4
BLAKE2b-256 37855c31c565c68807e525cb268d783e62b1f4a46b97d301d991f6b4ffbd52d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for cmap-0.7.2.tar.gz:

Publisher: ci.yml on pyapp-kit/cmap

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

File details

Details for the file cmap-0.7.2-py3-none-any.whl.

File metadata

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

File hashes

Hashes for cmap-0.7.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ad85bcc2327351bb72ff41516d4116d74b0af89258b35a323fcccb655a64f1f2
MD5 271fa67fc65fb1ac2caad9a39d631334
BLAKE2b-256 28b60f760b625233ae39ed7df1069e11edd8c2f8807acac75e40f6228507238c

See more details on using hashes here.

Provenance

The following attestation bundles were made for cmap-0.7.2-py3-none-any.whl:

Publisher: ci.yml on pyapp-kit/cmap

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