Utility functions for working with colors in Python.
If you don't have matplotlib and numpy installed with Python 3:
pip3 install -r requirements.txt
- Import what we need:
import matplotlib.pyplot as plt
import color_utils
- 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']
- Convert them to RGB values matplotlib can use (on [0, 1]):
rgbs = color_utils.hex_to_rgb_color_list(my_colors)
- Create your colormap:
my_cmap = color_utils.blended_cmap(rgbs)
- Visualize your colormap:
cbar = color_utils.draw_cmap(my_cmap)
plt.show()
- The colormap: