Colormaps
Colormaps is a library of collection of colormaps or color palettes for Python. It's written in Python with matplotlib and numpy as dependencies. You can use Colormaps to customize matplotlib plots.
Colormaps has colormaps or color palettes from:
- cartocolors
- cmocean
- colorbrewer
- cubehelix
- ncar ncl
- scientific
- tableau
- carbonplan
- cmasher
may be more
Docs: https://pratiman-91.github.io/colormaps/
Getting started
Dependencies
Python with:
- matplotlib
- numpy
Installation
pip install colormaps
or using conda
conda install colormaps -c conda-forge`
or using mamba
mamba install colormaps
or you can also use GitHub repo
git clone https://github.com/pratiman-91/colormaps.git
cd colormaps
python setup.py install
Using Colormaps
- Importing Colormaps
import colormaps as cmaps
cmaps.drought_severity
cmaps.ice
- Reverse the colormap
cmaps.ice_r
- Getting discrete number of levels
cmaps.ice.discrete(10)
- Shifting the colormap
cmaps.ice.shift(0.5)
- Shifting and then discrete levels
cmaps.ice.shift(0.5).discrete(10)
- Discrete levels then cut the colormap from left side
cmaps.ice.discrete(11).cut(0.25, 'left')
- Concatenate two or more colormaps
from colormaps.utils import concat
concat1 = concat(["ice", "BkBlAqGrYeOrReViWh200"])
- Concatenate two or more colormaps based on ratio
from colormaps.utils import concat
concat2 = concat([cmaps.ice, cmaps.BkBlAqGrYeOrReViWh200], ratios=[0.25,0.75])
- Concatenate two or more colormaps with granular support
from colormaps.utils import concat
concat3 = concat(
["ice", "thermal"],
ratios=[0.4, 0.6],
trim=[0.1, 0.05],
discrete=128,
name="my_concat"
)
- Matplotlib usage example
import matplotlib.pyplot as plt
import colormaps as cmaps
import numpy as np
x = y = np.arange(-3.0, 3.01, 0.05)
X, Y = np.meshgrid(x, y)
sigmax = sigmay = 1.0
mux = muy = sigmaxy=0.0
Xmu = X-mux
Ymu = Y-muy
rho = sigmaxy/(sigmax*sigmay)
z = Xmu**2/sigmax**2 + Ymu**2/sigmay**2 - 2*rho*Xmu*Ymu/(sigmax*sigmay)
denom = 2*np.pi*sigmax*sigmay*np.sqrt(1-rho**2)
Z = np.exp(-z/(2*(1-rho**2))) / denom
plt.pcolormesh(X,Y,Z,cmap=cmaps.cubehelix3_16_r)
plt.colorbar()
- Using concat in matplotlib
# Create sample data
X = np.linspace(-np.pi, np.pi, 100)
Y = np.linspace(-np.pi, np.pi, 100)
X, Y = np.meshgrid(X, Y)
Z = np.sin(X) * np.cos(Y)
# Plot with a colormap
fig, axes = plt.subplots(1, 2, figsize=(10, 4))
# Using ice colormap
im1 = axes[0].pcolormesh(X, Y, Z, cmap=cmaps.ice, shading='auto')
axes[0].set_title("Using cmaps.ice")
plt.colorbar(im1, ax=axes[0])
# Using a custom concatenated colormap
custom_cmap = concat(["thermal", "ice"], ratios=[0.4, 0.6])
im2 = axes[1].pcolormesh(X, Y, Z, cmap=custom_cmap, shading='auto')
axes[1].set_title("Using concat(['thermal', 'ice'])")
plt.colorbar(im2, ax=axes[1])
- Register maps with matplotlib
_ = cmaps.ice # registers "ice" with matplotlib
_ = cmaps.thermal # registers "thermal" with matplotlib
X = np.linspace(-np.pi, np.pi, 100)
Y = np.linspace(-np.pi, np.pi, 100)
X, Y = np.meshgrid(X, Y)
Z = np.sin(X) * np.cos(Y)
fig, axes = plt.subplots(1, 2, figsize=(10, 4))
im1 = axes[0].pcolormesh(X, Y, Z, cmap="ice", shading='auto')
axes[0].set_title('cmap="ice" (registered by colormaps)')
plt.colorbar(im1, ax=axes[0])
im2 = axes[1].pcolormesh(X, Y, Z, cmap="thermal", shading='auto')
axes[1].set_title('cmap="thermal" (registered by colormaps)')
plt.colorbar(im2, ax=axes[1])
plt.tight_layout()
- Register collections with matplotlib
# Register a single collection up front
cmaps.register_collection('cmocean')
# Now use by string name without prior attribute access
X = np.linspace(0, 1, 100)
Y = np.linspace(0, 1, 100)
X, Y = np.meshgrid(X, Y)
Z = np.sin(np.pi * X) * np.cos(np.pi * Y)
fig, axes = plt.subplots(1, 2, figsize=(10, 4))
im1 = axes[0].pcolormesh(X, Y, Z, cmap="ice", shading='auto')
axes[0].set_title('cmap="ice" via register_collection("cmocean")')
plt.colorbar(im1, ax=axes[0])
cmaps.register_all()
im2 = axes[1].pcolormesh(X, Y, Z, cmap="amber", shading='auto')
axes[1].set_title('cmap="amber" via register_all()')
plt.colorbar(im2, ax=axes[1])
plt.tight_layout()
Finding Colormaps
Colormaps are pre-built and loaded at the time of importing.
- Show different collections
from colormaps.utils import show_cmaps_collection
show_cmaps_collection(collection='cmasher')
- Show all collections
from colormaps.utils import show_cmaps_all
show_cmaps_all()
This is just a sample! You will get a long list of all possible colormap collections.
Metadata
Release files for colormaps 0.5.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 |
|---|---|---|---|---|
| colormaps-0.5.0.tar.gz | 484.5 kB | Without provenance | Details for colormaps-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| colormaps-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for colormaps-0.5.0-py3-none-any.whl |
Total release size: 1.2 MB
Release files / colormaps-0.5.0.tar.gz
| Download URL | colormaps-0.5.0.tar.gz |
|---|---|
| Size | 484.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
001e5c6cab426f88cc69a9dba1963c54a4292d7a63f37915be348b12aa27ef60
|
|
BLAKE2b-256 checksum How to use checksums |
bb023a5e2673f18f0a9d73c6ed69b34cf082e25b78755226df6af50484afe2df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / colormaps-0.5.0-py3-none-any.whl
| Download URL | colormaps-0.5.0-py3-none-any.whl |
|---|---|
| Size | 688.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8dc696714e06515b24e53bf066e98b35e84f14ec81155bcde60428c758da56a9
|
|
BLAKE2b-256 checksum How to use checksums |
d5396cfdbf15dda96dabd9110e63c814cd44e25a8e928d47a3973d646ac90f58
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for colormaps 0.5.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.