Skip to main content

Please see : http://colormap.readthedocs.io/ for an up-to-date documentation.

https://badge.fury.io/py/colormap.svg https://github.com/cokelaer/colormap/actions/workflows/ci.yml/badge.svg?branch=main https://coveralls.io/repos/cokelaer/colormap/badge.png?branch=main https://static.pepy.tech/personalized-badge/colormap?period=month&units=international_system&left_color=black&right_color=orange&left_text=Downloads Documentation Status
version:

Python 3.9, 3.10, 3.11, 3.12

contributions:

Please join https://github.com/cokelaer/colormap

issues:

Please use https://github.com/cokelaer/colormap/issues

notebook:

Please see https://github.com/cokelaer/colormap/tree/main/notebooks

What is it ?

colormap package provides utilities to convert colors between RGB, HEX, HLS, HUV and a framework to easily create and build colormaps for matplotlib. All matplotlib colormaps and some R colormaps are also available altogether. The plot_colormap method (see below) is handy to quickly pick up a colormaps and the test_colormap is useful to see a live version of the new colormap.

Installation

pip install colormap

Usage examples

  1. convert RGB to HEX:

from colormap import rgb2hex, hex2rgb

hex_color = rgb2hex(255, 0, 0)  # Red color in HEX
print(hex_color)  # Output: "#ff0000"

rgb_color = hex2rgb("#ff0000")  # Convert back to RGB
print(rgb_color)  # Output: (255, 0, 0)
  1. Generate a Custom colormap:

Create your own colormap. For instance, from red to green colors with intermediate color as whitish (diverging map from red to green):

from colormap import Colormap
c = Colormap()
mycmap = c.cmap( {'red':[1,1,0], 'green':[0,1,.39], 'blue':[0,1,0]})
cmap = c.test_colormap(mycmap)

Even simpler if the colormap is linear using color’s name:

from colormap import Colormap
c = Colormap()
mycmap = c.cmap_linear('red', 'white', 'green(w3c)')
cmap = c.test_colormap(mycmap)
https://colormap.readthedocs.io/en/latest/_images/quickstart-6.png
  1. Visualise existing matplotlib colormap:

from colormap import plot_colormap, plot_category
plot_colormap("viridis")

Using the Colormap instance, you can see all valid names using:

c.colormaps

Matplotlib is very well known in the PYthon ecosystem and has categorised colormaps into categories such as a “diverging”. To visualise all of them:

plot_category('diverging')
https://colormap.readthedocs.io/en/latest/_images/quickstart-4.png

Other sets of colormaps are : sequentials, sequentials2, misc, diverging, qualitative

See online documentation for details: http://colormap.readthedocs.io/

changelog

Version

Description

1.3.0

  • support for poetry 2.0 thanks to @cjwatson PR#26

  • Slightly better doc

1.2.0

1.1.0

  • switch to pyproject. remove easydev dependency. compat for python 3.11 and 3.12

1.0.6

  • Fix a matplotlib deprecation

  • Fix RTD documentation

1.0.5

Release files for colormap 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for colormap 1.3.0
File Size Uploaded
colormap-1.3.0.tar.gz 17.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for colormap 1.3.0
File Interpreter ABI Platform
colormap-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 34.4 kB

Release files / colormap-1.3.0.tar.gz

Download URL colormap-1.3.0.tar.gz
Size 17.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8df95ee498257aeabd3c8f42b55eac9a095fbfa05fbcbe5ac751fc95d71b00da
BLAKE2b-256 checksum
How to use checksums
27d69e425638d5c46926e9c508731284fd5a04043f63f8a4a4850947933da885
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release files / colormap-1.3.0-py3-none-any.whl

Download URL colormap-1.3.0-py3-none-any.whl
Size 17.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
75a158fdc2d06e81bb92568d070119f1a55a8028050dffbb1de196020a11292b
BLAKE2b-256 checksum
How to use checksums
c5f4c53ac42d8933014ad96266fe6ea86af2c96fa186f209d4f80f3ce227a55a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.6

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.9.10

1 release file

0.9.9

1 release file

0.9.8

1 release file

0.9.7

1 release file

0.9.6

1 release file

0.9.5

1 release file

0.9.4

1 release file

0.9.3

1 release file

0.9.2

1 release file

0.9.1

1 release file

0.9.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page