Background image

Generating an RGB colour scheme for a heat map

September 23rd, 2013

Recently, we have been experimenting with heat maps using jjguy’s Python module, which, in turn, is based on the Gheat library.

Jjguy’s script comes with five default color schemes, the same ones that Gheat ships with. While these default schemes are ok for demo purposes, we wanted to use a custom color scale instead.

Being no mathematician, I was lucky enough to find the algorithm for interpolating RGB values. With the help of this algorithm, I created a simple PHP script to generate the 256 colors that the heat map needed.

At the outset, I declare three arrays: the start color, the mid-point color and the target color, all in RGB. The script calculates the rest. I was really happy with the result: colors turned out nicely and this was pretty much the first time I had done such math since high school!

The PHP code can be found as a GitHub Gist – hope someone else will find this useful too!

Tags: , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

Latest comments

Tapio Nurminen on Vuoden 2013 kuntakartta SVG-muodossa

Kartta on vapaasti hyödynnettävissä, mutta lisenssiehdot kannattaa varmistaa Kuntaliitolta.

Arvi Leino on Vuoden 2013 kuntakartta SVG-muodossa

Kartalle on latauslinkki. Onko kartta vapaasti hyödynnettävissä esim. CC By 4.0 käyttöluvalla? ht...