Skip to main content

Scientific colormaps for making accessible, informative and 'cmashing' plots

Project description

PyPI - Latest Release PyPI - Python Versions Travis CI - Build Status AppVeyor - Build Status ReadTheDocs - Build Status CodeCov - Coverage Status JOSS - Submission Status

CMasher: Scientific colormaps for making accessible, informative and cmashing plots

The CMasher package provides a collection of scientific colormaps to be used by different Python packages and projects, mainly in combination with matplotlib, showcased in the online documentation. The colormaps in CMasher are all designed to be perceptually uniform sequential using the viscm package; most of them are color-vision deficiency friendly; and they cover a wide range of different color combinations to accommodate for most applications. It offers several alternatives to commonly used colormaps, like chroma and rainforest for jet; sunburst for hot; neutral for binary; and fusion and redshift for coolwarm. If you cannot find your ideal colormap, then please open an issue, provide the colors and/or style you want, and I will try to create one to your liking! Let’s get rid of all bad colormaps in the world together!

If you use CMasher for your work, then please star the repo, such that I can keep track of how many users it has and more easily raise awareness of bad colormaps.

Colormap overview

Below is an overview of all the colormaps that are currently in CMasher (made with the cmr.create_cmap_overview() function). For more information, see the online documentation.

CMasher Colormap Overview

Installation & Use

How to install

CMasher can be easily installed by either cloning the repository and installing it manually:

$ git clone https://github.com/1313e/CMasher
$ cd CMasher
$ pip install .

or by installing it directly from PyPI with:

$ pip install cmasher

CMasher can now be imported as a package with import cmasher as cmr.

Example use

The colormaps shown above can be accessed by simply importing CMasher. This makes them available in the cmasher module, in addition to registering them in matplotlib’s cm module (with added 'cmr.' prefix to avoid name clashes). So, for example, if one were to use the rainforest colormap, this could be done with:

# Import CMasher to register colormaps
import cmasher as cmr

# Import packages for plotting
import matplotlib.pyplot as plt
import numpy as np

# Access rainforest colormap through CMasher or MPL
cmap = cmr.rainforest                   # CMasher
cmap = plt.get_cmap('cmr.rainforest')   # MPL

# Generate some data to plot
x = np.random.rand(100)
y = np.random.rand(100)
z = x**2+y**2

# Make scatter plot of data with colormap
plt.scatter(x, y, c=z, cmap=cmap, s=300)
plt.show()

Accessing the colormaps in other packages than matplotlib would require reading in the text files in the cmasher/colormaps directory, which contain the normalized RGB values (multiply by 255 for regular 8-bit values) of every colormap, and registering them in the package manually. For those that are interested, the viscm source files that were used for creating the colormaps can also be found in the cmasher/colormaps directory in the repo (the source files are not provided with the package distribution). Note that my modified version of viscm (available here) is required in order to properly view and edit the source file of a diverging colormap.

Using custom colormaps

CMasher allows for custom colormaps to be imported with the cmr.import_cmaps function (which is executed automatically on the cmasher/colormaps directory when CMasher is imported). This function takes the path to a colormap file named cm_<cmap_name> (or the path to a directory containing such files); creates a matplotlib Colormap object using the data in the file; and registers it in matplotlib with the name 'cmr.<cmap_name>' (it will also be available in CMasher as cmr.cm.<cmap_name>). A colormap file can either be a JSCM-file as created by viscm or a text file that contains the normalized RGB values of the colormap (see the text files in the cmasher/colormaps directory for the structure of such files).

Note that colormaps imported this way cannot be accessed through CMasher using cmr.<cmap_name>, unlike CMasher’s own colormaps, but solely using cmr.cm.<cmap_name> (access through matplotlib is unchanged). This is to keep official and unofficial colormaps separated in CMasher.

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

cmasher-1.3.0.tar.gz (288.2 kB view details)

Uploaded Source

Built Distributions

cmasher-1.3.0-py3-none-any.whl (293.8 kB view details)

Uploaded Python 3

cmasher-1.3.0-py2-none-any.whl (293.8 kB view details)

Uploaded Python 2

File details

Details for the file cmasher-1.3.0.tar.gz.

File metadata

  • Download URL: cmasher-1.3.0.tar.gz
  • Upload date:
  • Size: 288.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.1.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/2.7.15

File hashes

Hashes for cmasher-1.3.0.tar.gz
Algorithm Hash digest
SHA256 c8cde087d93cc893bb5be9176101a497e1e14d804e981463798cbc2ca6aeac4b
MD5 55b83a56da33b61722ea4ac0fdef48d4
BLAKE2b-256 641c4048f32b076e063e24e73027f14daf9e2bdb7a42bfde554d5e5349b5708b

See more details on using hashes here.

File details

Details for the file cmasher-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: cmasher-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 293.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.5.6

File hashes

Hashes for cmasher-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 75997ab44314965633236361aa12072f1093bacab78bc832c00a376a7b4de765
MD5 87fb90de19ffde981f9cc77a94c5baca
BLAKE2b-256 0bfc100f0ae372596666c92aa084b1cf0fe9d1a3b5a64c2d5ee9eb3e8114037a

See more details on using hashes here.

File details

Details for the file cmasher-1.3.0-py2-none-any.whl.

File metadata

  • Download URL: cmasher-1.3.0-py2-none-any.whl
  • Upload date:
  • Size: 293.8 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.1.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/2.7.15

File hashes

Hashes for cmasher-1.3.0-py2-none-any.whl
Algorithm Hash digest
SHA256 6df3d4e39254290ce694f500e709cda6953d4fb4d2ba3e742360022b08e18645
MD5 1db0b5eeda7c5b0bc376ae5590f568f5
BLAKE2b-256 d6b83c00e109c33aa0018f19dc0034700dc986d015543e889f007e666909d408

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