What's new

About color

Nov 12, 2020

Samantha's color palettes

I was looking for suitable color maps the other day when trying to squeeze too much data into a plot. Usually I prefer to just remove some details for the sake of clarity, but even then, color matters.

Procrastinating away the afternoon, I stumbled upon this super nice article on color palettes by Samantha Zhang. She gives a comprehensive overview of aspects to consider when picking colors, such as how to make your plots accessible to colorblind readers. Best of all, she provides a long list of resources, links and tools that help with the process.

Since then, Samantha’s article became my go-to resource on color in data science, and I am currently testing out three of her color maps in a paper draft. Below you find a python snippet to mimic them in matplotlib.

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap

custom_cmaps = dict()
custom_cmaps["cold"] = [
    (0, "white"),
    (0.25, "#DCEDC8"),
    (0.45, "#42B3D5"),
    (0.75, "#1A237E"),
    (1, "black"),
custom_cmaps["hot"] = [
    (0, "white"),
    (0.3, "#FEEB65"),
    (0.65, "#E4521B"),
    (0.85, "#4D342F"),
    (1, "black"),
custom_cmaps["pinks"] = [
    (0, "white"),
    (0.2, "#FFECB3"),
    (0.45, "#E85285"),
    (0.65, "#6A1B9A"),
    (1, "black"),

def cmap_for_mpl(colors, n_bins=512):
    return LinearSegmentedColormap.from_list("custom_cmap", colors, N=n_bins)

# for functions that use color map objects
cmap = cmap_for_mpl(custom_cmaps["pinks"])

# or to get discrete color values, call cmap() with a value between 0 and 1
num_lines = 5
for idx in range(num_lines):
    clr = cmap((idx + 1) / (num_lines + 1))
    x = np.arange(100)/np.pi
    plt.plot(x, np.sin(x + idx*np.pi/4) + idx, label=idx, color=clr)


COVID-19 Inference and Forecast

How Effective are Interventions?

May 17, 2020

Our paper about estimating the effects of governmental interventions on the spread of COVID-19 is now out in Science!


Over the past months, my colleagues and I have worked on modeling the COVID-19 spread in Germany. Our approach uses Bayesian inference and Markov-Chain Monte-Carlo sampling on an SIR-model to find epidemiological parameters. It allows us to identify change points in the spreading rate (that is, when and how much the spreading rate changes). Check the links below for all the details!

[Science] [ArXiv] [GitHub]

I want to take the opportunity to thank everyone involved for this amazing collaboration. This has been, and still is, a truly great team effort. I feel that we have made a valuable contribution, and for me personally, the project made quarantine and working from home much more enjoyable! Thanks guys!

Website Content from Markdown

May 15, 2020

Time to celebrate, this is my first content that uses the new format.

For a while I have been noticing that it feels too cumbersome to add content to this site; writing is hard and it is harder when you do it in html. Then there is markdown, which feels completely opposite. It is convenient, easy to read and easy to write in any editor. You can even write a paper with colleagues in real time, without ever leaving your browser. Seriously, if you are not familiar with markdown yet, let me recommend spending a few minutes of procrastination to check it out.

Considering the goal to get markdown files onto my custom site, the only hurdle was to render the .md files to html. First, I considered parsing only once before uploading everything so that page loads remain snappy. Then I realized that parsing an average document takes less than 10ms and ended up using Parsedown, a render in php. This allows me to simply drop the .md files into a folder on the server, php fetches them and parsedown creates the html for every file.

See this snippet of php:

foreach (glob("folder_with_markdown_files/*.md") as $file) {
    $html = Parsedown::instance()->text(file_get_contents($file));
    echo "<hr><div class='markdown'>";
    echo $html;
    echo "</div>";

Related things to check out