Skip to content

stefmolin/Custom-Colormaps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Easily create your own colormaps

Utility functions for working with colors in Python.

Setup

If you don't have matplotlib and numpy installed with Python 3:

pip3 install -r requirements.txt

Usage

  1. Import what we need:
import matplotlib.pyplot as plt
import color_utils
  1. Define your colors with their hex codes (you can omit '#' and use 3 digit shorthand) in the order you wish them to appear:
my_colors = ['#800080', '#FFA500', '#FFFF00']
  1. Convert them to RGB values matplotlib can use (on [0, 1]):
rgbs = color_utils.hex_to_rgb_color_list(my_colors)
  1. Create your colormap:
my_cmap = color_utils.blended_cmap(rgbs)
  1. Visualize your colormap:
cbar = color_utils.draw_cmap(my_cmap)
plt.show()
  1. The colormap:

Multi-color colormap