Skip to content

Instantly share code, notes, and snippets.

@nbren12
Last active April 14, 2022 07:07
Show Gist options
  • Save nbren12/585e73cb5543568bc83f220f85890870 to your computer and use it in GitHub Desktop.
Save nbren12/585e73cb5543568bc83f220f85890870 to your computer and use it in GitHub Desktop.
Colorblind friendly defaults
# https://davidmathlogic.com/colorblind/#%23000000-%23E69F00-%2356B4E9-%23009E73-%23F0E442-%230072B2-%23D55E00-%23CC79A7
wong_palette = [
"#000000",
"#E69F00",
"#56B4E9",
"#009E73",
"#F0E442",
"#0072B2",
"#D55E00",
"#CC79A7",
]
# altair
import altair
def my_theme():
return {"config": {"range": {"category": wong_palette}}}
altair.themes.register("my_theme", my_theme)
altair.themes.enable("my_theme")
# plotly express
import plotly.express as px
px.defaults.color_discrete_sequence = wong_palette
# matplotlib
import matplotlib.pyplot as plt
from cycler import cycler
plt.rcParams["axes.prop_cycle"] = cycler("color", wong_palette)
@nbren12
Copy link
Author

nbren12 commented Dec 14, 2021

for i in range(1, 9):
    x = np.linspace(0, 1, 100)
    plt.plot(x, x*(1+i/8), label=str(i))
plt.legend()

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment