Import morpc package¶
import morpc
from matplotlib_inline.backend_inline import set_matplotlib_formats
Get colors with morpc.color.get_colors()¶
morpc.color.plot_from_hex_list(morpc.color.get_colors().QUAL(n=4))

Standard Palettes¶
morpc.palette.SEQ.keys()
dict_keys(['lightgreen', 'lightgreen_r', 'darkblue', 'darkblue_r', 'bluegreen', 'bluegreen_r', 'darkgreen', 'darkgreen_r', 'blue', 'blue_r', 'midblue', 'midblue_r', 'purple', 'purple_r', 'yellow', 'yellow_r', 'tan', 'tan_r', 'red', 'red_r', 'darkgrey', 'darkgrey_r', 'lightgrey', 'lightgrey_r'])
set_matplotlib_formats('svg')
%matplotlib inline
for color in morpc.palette.SEQ.keys():
if not color.endswith('_r'):
key = morpc.color.get_colors().morpc_colors[color]['key']['position']
morpc.color.plot_from_hex_list(morpc.palette.SEQ[color], labels=['hex'], position=key, title=color)
morpc.palette.SEQ2.keys()
dict_keys(['blue-lightgreen', 'bluegreen-darkblue', 'bluegreen-purple', 'yellow-darkblue', 'yellow-blue', 'yellow-darkgreen', 'yellow-lightgreen', 'yellow-red', 'yellow-purple', 'tan-lightgreen', 'tan-lightgrey', 'red-blue', 'red-lightgreen', 'purple-blue', 'purple-lightgrey'])
for color in morpc.palette.SEQ2.keys():
morpc.color.plot_from_hex_list(morpc.palette.SEQ2[color], title=color, labels=['hex'])
morpc.palette.DIV.keys()
dict_keys(['red-yellow-lightgreen', 'red-yellow-blue', 'red-lightgrey-blue', 'yellow-lightgrey-darkblue', 'lightgreen-lightgrey-purple', 'darkgreen-lightgrey-darkblue'])
for color in morpc.palette.DIV.keys():
morpc.color.plot_from_hex_list(morpc.palette.DIV[color], title=color, labels=['hex'])
morpc.color.plot_from_hex_list(morpc.palette.QUAL['morpc_ext'], labels=['hex'])
morpc.color.plot_from_hex_list(morpc.palette.QUAL['light'], labels=['hex'])
morpc.color.plot_from_hex_list(morpc.palette.QUAL['dark'], labels=['hex'])
morpc.color.plot_from_hex_list(morpc.palette.QUAL['paired'])
morpc.color.plot_from_hex_list(morpc.palette.QUAL['triples'])
Get standard HEX color codes¶
The get_colors() 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.get_colors().morpc_colors['darkblue']
Key Colors¶
The standard colors are retrieved using .KEYS
instance.
morpc.color.get_colors().KEYS
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.get_colors().KEYS.values(), labels=['hex'])
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.get_colors().SEQ('midblue')
morpc.color.plot_from_hex_list(morpc.color.get_colors().SEQ('midblue'))
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.get_colors().SEQ2(['yellow', 'darkgreen']), labels=[])
morpc.color.plot_from_hex_list(morpc.color.get_colors().SEQ2(['red', 'purple']), labels=[])
Three color sequential gradients¶
The same can be done with three colors using .SEQ3()
method.
morpc.color.plot_from_hex_list(morpc.color.get_colors().SEQ3(['yellow', 'lightgreen', 'darkblue']), labels=[])
morpc.color.plot_from_hex_list(morpc.color.get_colors().SEQ3(['yellow', 'red', 'purple']), labels=[])
morpc.color.plot_from_hex_list(morpc.color.get_colors().SEQ3(['purple', 'bluegreen', 'darkblue']), labels=[])
morpc.color.plot_from_hex_list(morpc.color.get_colors().SEQ3(['lightgrey', 'lightgreen', 'darkgreen']), 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.get_colors().DIV(['darkgreen', 'lightgrey','darkblue']), 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.plot_from_hex_list(morpc.color.get_colors().QUAL(6).hex_list, labels=[])
Testing color maps for color blindness accessibility¶
morpc.color.get_continuous_cmap(morpc.palette.DIV['darkgreen-lightgrey-darkblue'])
import numpy as np
import matplotlib.pyplot as plt
cmap = morpc.color.get_continuous_cmap(morpc.palette.DIV['lightgreen-lightgrey-purple'])
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='d')
Update to MORP Color Palette¶
import morpc
hex_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 morpc
greys = [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)
hue
hls = 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] = v
import json
with open('../morpc/color/morpc_colors.json', 'w') as file:
json.dump(morpc_colors, file, indent=3)