Scientific colormaps for making accessible, informative and 'cmashing' plots
Project description
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.
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()
If one instead wishes to use a specific CMasher colormap without adding dependencies (useful for, e.g., handing in tutorial assignments; quickly sharing work/results with someone; etc.), then one can find stand-alone versions of all colormaps, named <cmap_name>/<cmap_name>.py, in the cmasher/colormaps directory. These Python modules can be placed in a local working directory, and can then be imported with import <cmap_name> (e.g., import rainforest to register the rainforest colormap in matplotlib as 'cmr.rainforest').
Accessing the colormaps in other languages than Python would require reading in the <cmap_name>/<cmap_name>_8bit.txt text files in the cmasher/colormaps directory, which contain the 8-bit RGB values of every colormap, and registering them in the appropriate package in the language 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). If one wishes to register a colormap using (normalized) RGB values that are already in memory, the cmr.register_cmap function can be used for this.
Note that colormaps imported/registered 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 the same as before). This is to keep official and unofficial colormaps separated in CMasher.
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 Distributions
File details
Details for the file cmasher-1.3.5.tar.gz
.
File metadata
- Download URL: cmasher-1.3.5.tar.gz
- Upload date:
- Size: 227.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e4c24db0d1fd257b4ba919098c1e1d82de5ba0e85759d880423966e2a8fa84a |
|
MD5 | ee6b2cc09eed572065e64dbd6f3751c4 |
|
BLAKE2b-256 | 9f08ef1725a7cef1b4545e19da60fe51c750f8e52021ba2e967e4a4feb957b6b |
File details
Details for the file cmasher-1.3.5-py3-none-any.whl
.
File metadata
- Download URL: cmasher-1.3.5-py3-none-any.whl
- Upload date:
- Size: 230.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.5.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9da9c69838a7d3d8f6aa6850509d5a4ddc0ba18dfbe426585324a450cee14c0 |
|
MD5 | 3d58fdeb076265333e7c05253c502cdb |
|
BLAKE2b-256 | 4a71b94723830855d31c50f6af206e490c1864f358a5e13a1b5f805a2a0078ee |
File details
Details for the file cmasher-1.3.5-py2-none-any.whl
.
File metadata
- Download URL: cmasher-1.3.5-py2-none-any.whl
- Upload date:
- Size: 230.9 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41c56f6ec3181b6b1936ccd4e2e84b8616ef3751efca0987dca859e14460ad65 |
|
MD5 | e71b302ef2f92b3beda0e63053fc8882 |
|
BLAKE2b-256 | 98180684e70134d6892f3e08ea0a0bc6422b88952fa45959b1ebb9a481b101e4 |