Skip to article frontmatterSkip to article content

morpc.color Demo

Import morpc package

import morpc

Standard Palettes

morpc.palette.SEQ.keys()
dict_keys(['darkblue', 'darkblue_r', 'midblue', 'midblue_r', 'blue', 'blue_r', 'bluegreen', 'bluegreen_r', 'darkgreen', 'darkgreen_r', 'lightgreen', 'lightgreen_r', 'darkgrey', 'darkgrey_r', 'lightgrey', 'lightgrey_r', 'yellow', 'yellow_r', 'tan', 'tan_r', 'red', 'red_r', 'purple', 'purple_r'])
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)
<Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes>
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'])
<Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes>
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'])
<Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes><Figure size 1100x200 with 1 Axes>
morpc.color.plot_from_hex_list(morpc.palette.QUAL['morpc_ext'], labels=['hex'])
<Figure size 1000x200 with 1 Axes>
morpc.color.plot_from_hex_list(morpc.palette.QUAL['light'], labels=['hex'])
<Figure size 1000x200 with 1 Axes>
morpc.color.plot_from_hex_list(morpc.palette.QUAL['dark'], labels=['hex'])
<Figure size 1000x200 with 1 Axes>
morpc.color.plot_from_hex_list(morpc.palette.QUAL['paired'])
<Figure size 2000x200 with 1 Axes>
morpc.color.plot_from_hex_list(morpc.palette.QUAL['triples'])
<Figure size 3000x200 with 1 Axes>

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': {'position': 8, 'pantone': '295 U'}, 'hls': {'hue': 0.594, 'sat': [0.1, 0.12, 0.15, 0.18, 0.22, 0.29, 0.33, 0.36, 0.44, 0.55, 0.46], 'greys': [0.95, 0.87, 0.78, 0.68, 0.58, 0.45, 0.39, 0.3, 0.21, 0.15, 0.08]}, 'gradient': {'rgb': [[0.9462890624999999, 0.950546875, 0.9560546875000001], [0.85890625, 0.8720884375, 0.889140625], [0.75657958984375, 0.784266015625, 0.82008056640625], [0.6393164062500001, 0.6872934375, 0.7493554687499999], [0.5153955078125, 0.591597578125, 0.6901708984375], [0.34563964843749995, 0.46874578125, 0.6279931640625], [0.28584594726562496, 0.40861464843749995, 0.567425537109375], [0.21187500000000004, 0.3157996875, 0.45023437499999996], [0.13275390625, 0.223709296875, 0.3413671875], [0.07877197265624997, 0.16272539062499997, 0.27132568359375003], [0.04904296875, 0.0854728125, 0.13259765625]], 'hex': ['#f1f2f3', '#dbdee2', '#c0c7d1', '#a3afbf', '#8396af', '#5877a0', '#486890', '#365072', '#213957', '#142945', '#0c1521']}}

Key Colors

The standard colors are retrieved using .KEYS instance.

morpc.color.get_colors().KEYS
{'darkblue': '#365072', 'midblue': '#34617a', 'blue': '#0077bf', 'bluegreen': '#00b0bc', 'darkgreen': '#2a7f67', 'lightgreen': '#5ab55f', 'darkgrey': '#727a82', 'lightgrey': '#aab1b6', 'yellow': '#f7a402', 'tan': '#ad5d44', 'red': '#e93e46', 'purple': '#b772b8'}

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'])
Loading...
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)
<Figure size 640x480 with 2 Axes>
from daltonize import daltonize
daltonize.simulate_mpl(fig, color_deficit='d')
<Figure size 640x480 with 2 Axes>

Update to MORP Color Palette

import morpc

Purple

hue = 0.832
sats =  [0.08, 0.14, 0.18, 0.26, 0.33, 0.42, 0.48, 0.44, 0.37, 0.3, 0.24]
greys = [0.95, 0.87, 0.78, 0.67, 0.56, 0.45, 0.33, 0.26, 0.20, 0.15, 0.08]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, greys)
morpc.color.plot_from_rgb_list(rgb_scale, position=6, labels=['hex'])
purple = {"purple": {
    "key": {
        "position": 5,
        "pantone": "7442 C"
    },
    "hls": {
        "hue": hue,
        "sat": sats,
        "greys": greys
    },
    "gradient": {
        "rgb": rgb_scale,
        "hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
    }
}
}

Red

hue = .992
sats =  [0.5,  0.54, 0.58, 0.64, 0.74,  0.80, 0.86, 0.89, 0.82, 0.76, 0.70]
greys = [0.95, 0.87, 0.78, 0.67, 0.56, 0.45, 0.33, 0.26, 0.20, 0.15, 0.08]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, greys)
morpc.color.plot_from_rgb_list(rgb_scale, position=7, labels=['hex'])
red = {"red": {
    "key": {
        "position": 6,
        "pantone": "185 C"
    },
    "hls": {
        "hue": hue,
        "sat": sats,
        "greys": greys
    },
    "gradient": {
        "rgb": rgb_scale,
        "hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
    }
}
}

Tan

hue = .04
sats =  [0.22,  0.26, 0.29, 0.35, 0.38,  0.43, 0.48, 0.50, 0.46, 0.42, 0.40]
greys = [0.95, 0.87, 0.78, 0.67, 0.56, 0.45, 0.33, 0.26, 0.20, 0.15, 0.08]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, greys)
morpc.color.plot_from_rgb_list(rgb_scale, position=5, labels=['hex'])
tan = {"tan": {
    "key": {
        "position": 6,
        "pantone": "7515 C"
    },
    "hls": {
        "hue": hue,
        "sat": sats,
        "greys": greys
    },
    "gradient": {
        "rgb": rgb_scale,
        "hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
    }
}
}

Yellow

hue = .110
sats =  [0.78, 0.84, 0.90, 0.98, 0.96, 0.93, 0.90, 0.87, 0.84, 0.80, 0.78]
greys = [0.95, 0.87, 0.78, 0.67, 0.58, 0.45, 0.33, 0.26, 0.20, 0.15, 0.08]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, greys)
morpc.color.plot_from_rgb_list(rgb_scale, labels=['hex'], position=4)
yellow = {"yellow": {
    "key": {
        "position": 4,
        "pantone": "137 C"
    },
    "hls": {
        "hue": hue,
        "sat": sats,
        "greys": greys
    },
    "gradient": {
        "rgb": rgb_scale,
        "hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
    }
}
}

Light Green

hue = .342
sats =  [0.12, 0.18, 0.22, 0.36, 0.39, 0.46, 0.58, 0.58, 0.44, 0.36, 0.28]
greys = [0.95, 0.87, 0.78, 0.66, 0.57, 0.45, 0.33, 0.26, 0.20, 0.15, 0.08]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, greys)
morpc.color.plot_from_rgb_list(rgb_scale, position=5, labels=['hex'])
lightgreen = {"lightgreen": {
    "key": {
        "position": 5,
        "pantone": "360 C"
    },
    "hls": {
        "hue": hue,
        "sat": sats,
        "greys": greys
    },
    "gradient": {
        "rgb": rgb_scale,
        "hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
    }
}
}

Dark Blue

hue = .594
greys = [0.95, 0.87, 0.78, 0.68, 0.58, 0.45, 0.39, 0.30, 0.21, 0.15, 0.08]
sats =  [0.10, 0.12, 0.15, 0.18, 0.22, 0.29, 0.33, 0.36, 0.44, 0.55, 0.46]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, greys)
morpc.color.plot_from_rgb_list(rgb_scale, position=8, labels=['hex'])
darkblue = {"darkblue": {
    "key": {
        "position": 8,
        "pantone": "295 U"
    },
    "hls": {
        "hue": hue,
        "sat": sats,
        "greys": greys
    },
    "gradient": {
        "rgb": rgb_scale,
        "hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
    }
}
}

Mid Blue

hue = .559
greys = [0.95, 0.87, 0.78, 0.68, 0.58, 0.46, 0.34, 0.28, 0.21, 0.15, 0.08]
sats =  [0.16, 0.18, 0.22, 0.26, 0.30, 0.34, 0.40, 0.37, 0.33, 0.30, 0.25]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, greys)
morpc.color.plot_from_rgb_list(rgb_scale, position=7, labels=['hex'])
midblue = {"midblue": {
    "key": {
        "position": 7,
        "pantone": "3025 U"
    },
    "hls": {
        "hue": hue,
        "sat": sats,
        "greys": greys
    },
    "gradient": {
        "rgb": rgb_scale,
        "hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
    }
}
}

Blue

hue = .5628
greys= [0.95, 0.87, 0.78, 0.68, 0.58, 0.43, 0.36, 0.28, 0.21, 0.15, 0.08]
sats=  [0.50, 0.64, 0.68, 0.74, 0.80, 0.84, 1.00, 1.00, 0.98, 0.92, 0.87]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, greys)
morpc.color.plot_from_rgb_list(rgb_scale, position=7, labels=['hex'])
blue = {"blue": {
    "key": {
        "position": 7,
        "pantone": "3005 U"
    },
    "hls": {
        "hue": hue,
        "sat": sats,
        "greys": greys
    },
    "gradient": {
        "rgb": rgb_scale,
        "hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
    }
}
}

Bluegreen

hue = .511
greys= [0.95, 0.87, 0.78, 0.68, 0.58, 0.49, 0.36, 0.28, 0.21, 0.15, 0.08]
sats=  [0.55, 0.68, 0.75, 0.86, 0.95, 1.00, 0.95, 0.93, 0.89, 0.85, 0.80]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, greys)
morpc.color.plot_from_rgb_list(rgb_scale, position=6, labels=['hex'])
bluegreen = {"bluegreen": {
    "key": {
        "position": 6,
        "pantone": "7466 U"
    },
    "hls": {
        "hue": hue,
        "sat": sats,
        "greys": greys
    },
    "gradient": {
        "rgb": rgb_scale,
        "hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
    }
}
}

Dark Green

hue = .453
greys= [0.95, 0.87, 0.78, 0.68, 0.58, 0.45, 0.39, 0.28, 0.21, 0.15, 0.08]
sats=  [0.16, 0.22, 0.28, 0.32, 0.36, 0.44, 0.50, 0.54, 0.54, 0.50, 0.46]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, greys)
morpc.color.plot_from_rgb_list(rgb_scale, position=7, labels=['hex'])
darkgreen = {"darkgreen": {
    "key": {
        "position": 7,
        "pantone": "3415 U"
    },
    "hls": {
        "hue": hue,
        "sat": sats,
        "greys": greys
    },
    "gradient": {
        "rgb": rgb_scale,
        "hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
    }
}
}

Light Green

hue = .3425
greys= [0.95, 0.87, 0.78, 0.68, 0.567, 0.45, 0.36, 0.28, 0.21, 0.15, 0.08]
sats=  [0.12, 0.18, 0.22, 0.32, 0.383, 0.46, 0.58, 0.58, 0.44, 0.36, 0.28]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, greys)
morpc.color.plot_from_rgb_list(rgb_scale, position=5, labels=['hex'])
lightgreen = {"lightgreen": {
    "key": {
        "position": 5,
        "pantone": "360 U"
    },
    "hls": {
        "hue": hue,
        "sat": sats,
        "greys": greys
    },
    "gradient": {
        "rgb": rgb_scale,
        "hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
    }
}
}

Dark grey

hue = .578
greys= [0.95, 0.87, 0.78, 0.68, 0.57, 0.475, 0.38, 0.28, 0.21, 0.15, 0.08]
sats=  [0.01, 0.03, 0.05, 0.06, 0.06, 0.067, 0.08, 0.08, 0.06, 0.04, 0.02]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, greys)
morpc.color.plot_from_rgb_list(rgb_scale, position=6, labels=['hex'])
darkgrey = {"darkgrey": {
    "key": {
        "position": 6,
        "pantone": "431 U"
    },
    "hls": {
        "hue": hue,
        "sat": sats,
        "greys": greys
    },
    "gradient": {
        "rgb": rgb_scale,
        "hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
    }
}
}

Light Grey

hue = .569
greys= [0.95, 0.87, 0.78, 0.69, 0.57, 0.475, 0.38, 0.28, 0.21, 0.15, 0.08]
sats=  [0.04, 0.06, 0.08, 0.076, 0.09, 0.09, 0.08, 0.08, 0.06, 0.04, 0.02]
rgb_scale = morpc.color.rgb_scale_from_hue(hue, sats, greys)
morpc.color.plot_from_rgb_list(rgb_scale, position=4, labels=['hex'])
lightgrey = {"lightgrey": {
    "key": {
        "position": 4,
        "pantone": "428 U"
    },
    "hls": {
        "hue": hue,
        "sat": sats,
        "greys": greys
    },
    "gradient": {
        "rgb": rgb_scale,
        "hex": morpc.color.rgb_list_to_hex_list(rgb_scale)
    }
}
}

Build JSON

darkblue
dicts = [darkblue, midblue, blue, bluegreen, darkgreen, lightgreen, darkgrey, lightgrey, yellow, tan, red, purple]
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)