Skip to content
/ cud Public

Color Universal Design colourblind-friendly python matplotlib palette

License

Notifications You must be signed in to change notification settings

mbhall88/cud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Color Universal Design colourblind-friendly python matplotlib palette

This repository contains a python file cud.py which contains a dictionary, list, and associated function for creating a palette based on the Color Universal Design.

- Hex Color
#000000 #000000 Black
#e69f00 #e69f00 Orange
#56b4e9 #56b4e9 Skyblue
#009e73 #009e73 Bluish Green
#f0e442 #f0e442 Yellow
#0072b2 #0072b2 Blue
#d55e00 #d55e00 Vermilion
#cc79a7 #cc79a7 Redish Purple

Usage

Copy and paste the contents of cud.py into your project and use the cud() function as follows.

The standard 8-colour palette

palette = cud()
plot_colourtable(palette)

standard palette

Or you can offset and start from the second colour

palette = cud(start=1)
plot_colourtable(palette)

offset palette

Or only select three colours

palette = cud(n=3)
plot_colourtable(palette)

three palette

See utils.py for the code used to generate the above plots.

A common usecase for such a palette would be with seaborn

import seaborn as sns
sns.set_theme(style="whitegrid")
penguins = sns.load_dataset("penguins")
palette = cud()
# Draw a nested barplot by species and sex
g = sns.catplot(
    data=penguins, kind="bar",
    x="species", y="body_mass_g", hue="sex",
    errorbar="sd", alpha=.6, height=6,
    palette=palette
)
g.despine(left=True)
g.set_axis_labels("", "Body mass (g)")
g.legend.set_title("")

seaborn palette