Import morpc package¶
import morpc
import logging
from morpc.logs import config_logs
config_logs('temp_data/color-demo.log', 'info')
logger = logging.getLogger(__name__)2026-01-26 11:37:13,030 | INFO | morpc.logs.config_logs: Set up logging save to file temp_data/color-demo.log
All Colors¶
import morpc.color
for color in morpc.color.morpc_colors:
morpc.color.plot_from_hex_list([x for x in morpc.color.morpc_colors[color].values()][1:], title=color)












Get colors with morpc.color.GetColors¶
Get standard HEX color codes¶
The GetColors class provides access to a json file that contains various useful definitions of colors. It takes one argument colorDictPath='../morpc/color/morpc_colors.json' which is the relative path to the json file.
The json file is stored in the attribute morpc_colors.
morpc.color.GetColors().morpc_colors['WarmGrey']{'KEY': '#B4AFAF',
'WG1': '#3d3d3d',
'WG2': '#656363',
'WG3': '#8B8989',
'WG4': '#B4AFAF',
'WG5': '#CDC9C9',
'WG6': '#EEE9E9'}Key Colors¶
The standard colors are retrieved using .KEYS instance.
morpc.color.GetColors().KEYS(){'Green': '#8DC63F',
'Forest': '#2F6338',
'Sky': '#74C3D5',
'Blue': '#064A8C',
'Ocean': '#0E4A5A',
'Navy': '#1A2E59',
'Brown': '#9A7E6D',
'Yellow': '#FFD912',
'Orange': '#DD6226',
'Red': '#C61A35',
'Purple': '#6B4A92',
'WarmGrey': '#B4AFAF',
'CoolGrey': '#AFB7BC'}Plot color strips from hex lists to see colors¶
You can plot a list of hex codes using the plot_from_hex_list() function. In the following example, we pass the values of the key colors to see them. The plot includes the HLS values, a grey values, and the hex code.
morpc.color.plot_from_hex_list(morpc.color.GetColors().KEYS().values())
Sequential color gradients for each color¶
Each color has an associated gradient. These gradients can be returned using the .SEQ() function. Simply pass the color name to the funcion.
morpc.color.GetColors().SEQ('Forest').hex_list['#001908',
'#0e3219',
'#1d4c2a',
'#265731',
'#2e6237',
'#357041',
'#3b7e4a',
'#539c66',
'#69b981',
'#91cca0',
'#b8dfbf']morpc.color.plot_from_hex_list(morpc.color.GetColors().SEQ('Forest').hex_list)
Two color sequential gradients¶
Pass a list of two color names to .SEQ2() method to get a split gradient.
morpc.color.plot_from_hex_list(morpc.color.GetColors().SEQ2(['Forest', 'Yellow']).hex_list)
morpc.color.plot_from_hex_list(morpc.color.GetColors().SEQ2(['Navy', 'WarmGrey']).hex_list)
Use hex_list_r to reverse the gradient
morpc.color.plot_from_hex_list(morpc.color.GetColors().SEQ2(['Purple', 'Red']).hex_list_r)
Three color sequential gradients¶
The same can be done with three colors using .SEQ3() method.
morpc.color.plot_from_hex_list(morpc.color.GetColors().SEQ3(['Navy', 'Forest', 'Yellow']).hex_list, labels=[])
morpc.color.plot_from_hex_list(morpc.color.GetColors().SEQ3(['Purple','Red','Yellow']).hex_list, labels=[])
morpc.color.plot_from_hex_list(morpc.color.GetColors().SEQ3(['Navy', 'Ocean', 'Purple']).hex_list, labels=[])
morpc.color.plot_from_hex_list(morpc.color.GetColors().SEQ3(['Forest', 'Yellow', 'WarmGrey']).hex_list, labels=[])
Diverging color gradients¶
Use the .DIV() method can be used to create diverging gradients and color maps.
morpc.color.plot_from_hex_list(morpc.color.GetColors().DIV(['Forest', 'CoolGrey', 'Navy'], 7).hex_list, labels=[])
Qualitative color groups¶
Use the .QUAL() method to return groups for qualitative data. It selects a number of grouped lightness variations of each color.
morpc.color.GetColors().QUAL(colors=['Navy', 'Green', 'Blue', 'Forest']).hex_list['#1A2E59', '#8DC63F', '#064A8C', '#2F6338']morpc.color.plot_from_hex_list(morpc.color.GetColors().QUAL(colors=['Navy', 'Green', 'Blue', 'Forest']).hex_list, labels=[])
morpc.color.plot_from_hex_list(morpc.color.GetColors().QUAL(colors=['Navy', 'Green', 'Blue', 'Forest'], paired=True).hex_list, labels=[])
Testing color maps for color blindness accessibility¶
morpc.color.colors.GetColors().DIV(['Purple', 'WarmGrey', 'Navy']).cmapimport numpy as np
import matplotlib.pyplot as plt
cmap = morpc.color.colors.GetColors().DIV(['Red', 'WarmGrey', 'Navy']).cmap
np.random.seed(19680801)
data = np.random.randn(30, 30)
fig, ax = plt.subplots()
psm = ax.pcolormesh(data, cmap=cmap, rasterized=True, vmin=-4, vmax=4)
fig.colorbar(psm, ax=ax)
from daltonize import daltonize
daltonize.simulate_mpl(fig, color_deficit='t')
DEPRECIATED - Update to MORP Color Palette¶
import morpchex_dict = {
'lightgreen': '#63E868',
'darkgreen': '#288064',
'bluegreen': '#00EEFF',
'blue': '#0076C5',
'midblue': '#00435E',
'darkblue': '#032451',
'yellow': '#FFCC29',
'red': '#E30911',
'purple': '#8D4E8D',
'tan': '#E6CEC3',
}
grey_dict = {
'lightgrey': '#B9BCBD',
'darkgrey': '#647078',
'white': '#FFFFFF',
'black': '#000000'
}morpc.color.plot_from_hex_list([v for k, v in grey_dict.items()])morpc.color.plot_from_hex_list([v for k, v in hex_dict.items()])import numpy as np
import morpcgreys = [x for x in np.linspace(.95, .05, 11)]Purple¶
hls = morpc.color.hex_to_hls(hex_dict['purple'])
hue = hls[0]
sats = [hls[2] for x in greys]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, greys)morpc.color.plot_from_rgb_list(rgb_scale, position=7)purple = {"purple": {
"key": {
"position": 7,
},
"hls": {
"hue": hue,
"sat": sats,
"greys": greys
},
"gradient": {
"rgb": rgb_scale,
"hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
}
}
}Red¶
hls = morpc.color.hex_to_hls(hex_dict['red'])
hue = hls[0]
sats = [hls[2] for x in greys]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, [x-.0246 for x in greys])
morpc.color.plot_from_rgb_list(rgb_scale, position=8)red = {"red": {
"key": {
"position": 8,
},
"hls": {
"hue": hue,
"sat": sats,
"greys": greys
},
"gradient": {
"rgb": rgb_scale,
"hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
}
}
}Tan¶
hls = morpc.color.hex_to_hls(hex_dict['tan'])
hue = hls[0]
sats = [hls[2]-0.0087 for x in greys]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, [x-0.026 for x in greys])
morpc.color.plot_from_rgb_list(rgb_scale, position=2)tan = {"tan": {
"key": {
"position": 2,
},
"hls": {
"hue": hue,
"sat": sats,
"greys": greys
},
"gradient": {
"rgb": rgb_scale,
"hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
}
}
}Yellow¶
morpc.color.plot_from_hex_list([hex_dict['yellow']])morpc.color.hex_to_hls('#FFCC29')morpc.color.hls_to_hex(0.127, 0.58, 1)huehls = morpc.color.hex_to_hls(hex_dict['yellow'])
hue = 0.127
sats = [1 for x in greys]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, [x+0.0175 for x in greys])
morpc.color.plot_from_rgb_list(rgb_scale, position=3)yellow = {"yellow": {
"key": {
"position": 3,
},
"hls": {
"hue": hue,
"sat": sats,
"greys": greys
},
"gradient": {
"rgb": rgb_scale,
"hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
}
}
}Light Green¶
hls = morpc.color.hex_to_hls(hex_dict['lightgreen'])
hue = hls[0]
sats = [hls[2] for x in greys]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, [x+0.018 for x in greys])
morpc.color.plot_from_rgb_list(rgb_scale, position=4)lightgreen = {"lightgreen": {
"key": {
"position": 4,
},
"hls": {
"hue": hue,
"sat": sats,
"greys": greys
},
"gradient": {
"rgb": rgb_scale,
"hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
}
}
}Dark Blue¶
hls = morpc.color.hex_to_hls(hex_dict['darkblue'])
hue = hls[0]
sats = [hls[2] for x in greys]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, [x-0.016 for x in greys])
morpc.color.plot_from_rgb_list(rgb_scale, position=10)darkblue = {"darkblue": {
"key": {
"position": 10,
},
"hls": {
"hue": hue,
"sat": sats,
"greys": greys
},
"gradient": {
"rgb": rgb_scale,
"hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
}
}
}Mid Blue¶
hls = morpc.color.hex_to_hls(hex_dict['midblue'])
hue = hls[0]
sats = [hls[2] for x in greys]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, [x-0.032 for x in greys])
morpc.color.plot_from_rgb_list(rgb_scale, position=9)midblue = {"midblue": {
"key": {
"position": 9,
},
"hls": {
"hue": hue,
"sat": sats,
"greys": greys
},
"gradient": {
"rgb": rgb_scale,
"hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
}
}
}Blue¶
hls = morpc.color.hex_to_hls(hex_dict['blue'])
hue = hls[0]
sats = [hls[2] for x in greys]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, [x-.05 for x in greys])
morpc.color.plot_from_rgb_list(rgb_scale, position=7)blue = {"blue": {
"key": {
"position": 7,
},
"hls": {
"hue": hue,
"sat": sats,
"greys": greys
},
"gradient": {
"rgb": rgb_scale,
"hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
}
}
}Bluegreen¶
hls = morpc.color.hex_to_hls(hex_dict['bluegreen'])
hue = hls[0]
sats = [hls[2] for x in greys]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, [x-0.018 for x in greys])
morpc.color.plot_from_rgb_list(rgb_scale, position=4)bluegreen = {"bluegreen": {
"key": {
"position": 4,
},
"hls": {
"hue": hue,
"sat": sats,
"greys": greys
},
"gradient": {
"rgb": rgb_scale,
"hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
}
}
}Dark Green¶
hls = morpc.color.hex_to_hls(hex_dict['darkgreen'])
hue = hls[0]
sats = [hls[2] for x in greys]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, [x-0.023 for x in greys])
morpc.color.plot_from_rgb_list(rgb_scale, position=7)darkgreen = {"darkgreen": {
"key": {
"position": 8,
},
"hls": {
"hue": hue,
"sat": sats,
"greys": greys
},
"gradient": {
"rgb": rgb_scale,
"hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
}
}
}Dark grey¶
hls = morpc.color.hex_to_hls(grey_dict['darkgrey'])
hue = hls[0]
sats = [hls[2] for x in greys]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, greys)
morpc.color.plot_from_rgb_list(rgb_scale, position=8)darkgrey = {"darkgrey": {
"key": {
"position": 8,
},
"hls": {
"hue": hue,
"sat": sats,
"greys": greys
},
"gradient": {
"rgb": rgb_scale,
"hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
}
}
}Light Grey¶
hls = morpc.color.hex_to_hls(grey_dict['lightgrey'])
hue = hls[0]
sats = [hls[2] for x in greys]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, greys)
morpc.color.plot_from_rgb_list(rgb_scale, position=3)lightgrey = {"lightgrey": {
"key": {
"position": 3,
},
"hls": {
"hue": hue,
"sat": sats,
"greys": greys
},
"gradient": {
"rgb": rgb_scale,
"hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
}
}
}Build JSON¶
dicts = [lightgreen, darkblue, bluegreen, darkgreen, blue, midblue, purple, yellow, tan, red, darkgrey, lightgrey]morpc_colors = {}
for d in dicts:
for k, v in d.items(): # d.items() in Python 3+
morpc_colors[k] = vimport jsonwith open('../morpc/color/morpc_colors.json', 'w') as file:
json.dump(morpc_colors, file, indent=3)