Skip to main content

Scientific colormaps for python, without dependencies

Project description

cmap

License PyPI 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 or cmocean in your python code, without having to install matplotlib or cmocean.

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 all of the open-source colormaps from matplotlib and cmocean, 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.

API

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.        ]])

Third Party Library Support

The cmap.Colormap object has convenience methods that allow it to be used with a number of third-party colormap objects (like matplotlib, vispy, napari, plotly, etc...).

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.0.1.tar.gz (564.5 kB view details)

Uploaded Source

Built Distribution

cmap-0.0.1-py3-none-any.whl (608.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cmap-0.0.1.tar.gz
  • Upload date:
  • Size: 564.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for cmap-0.0.1.tar.gz
Algorithm Hash digest
SHA256 56841f45692d8847b3475d78083c4e12ae6bf140f63fe1158b61e36338b0248f
MD5 b4fc3c715048bd2304d360a177c2fa5e
BLAKE2b-256 b900f84ba37fa77b0ab5ab44ed79ccb68ac83c4cf7c186978649ce3f7e65d3b9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cmap-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 608.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for cmap-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bdb8597ad1a90f8de67dbdb872f56a8341095054b18ed583bc0dea42a6c63b2a
MD5 739929442bd9df88ffc5da91f586ccc6
BLAKE2b-256 92e14826225a92453ce76eb0fee6c72e79ca0cf8ba0ba73fc50a158e4d7d1b95

See more details on using hashes here.

Supported by

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