nextstrain / forecasts-ncov

SARS-CoV-2 variant growth rates and frequency forecasts
https://nextstrain.org/sars-cov-2/forecasts/
7 stars 2 forks source link

Update lineage colour definitions #66

Closed jameshadfield closed 10 months ago

jameshadfield commented 10 months ago

Before (top) / after (bottom) images, using the same underlying data:

image

image

And here's a cartoon image showing mapping between clades and lineages:

image

I'll make a subsequent PR aimed at preventing the clade colour definitions from becoming out-of-sync with the lineage ones.

trvrb commented 10 months ago

Definite improvement here. Please feel free to merge. One comment however: previously I've found it very useful to take a hex color (like #A6BE55 for clade 23C) and call Darker() and Lighter() to get a spectrum of shades/tints relative to a baseline color. Here instead you've had to figure out a rough mapping from hex values to supported color ramps like {'name': 'YlOrRd', 'start': 0.5, 'stop': 0.6}.

Even if there's not a friendly built-in function to do this in Python, you should be able to do math on the hex values to accomplish this, ala this gist. Here's the block of code I used to pad out shades and tints from a base color using Darker and Lighter: color_mapping

jameshadfield commented 10 months ago

Yeah - there's plenty of python libraries which will help with this. I'm going to merge this as-is, and the subsequent PR should bring the clade colour (hex) definitions into this script which will provide a platform to experiment with different colour ramps more easily.