Sitemap
Sam Stack

Sam Stack

The Data Dork

Situational Shading

3 min readJan 16, 2019

--

Press enter or click to view image in full size
Seaborns cmap options : “Reds”, “Blues”, “Plasma”, “Rainbow”, ”gist_ncar”

In a recent project I was working on, I created a heatmap to show count densities of two overlapping categorical features. However, the resulting heatmap was not what I really wanted. I was very interested in cells that were white or very light to indicate very low to 0 counts, but because of the range and odd distribution of my data, this did not turn out as expected.

Press enter or click to view image in full size
Heatmap with standard scale shading

Anything thats not on the top-left to bottom-right diagonal is hard to gain insight from because it is all just too light!

My Solution was to modify the gradient by which the colors were generated.
Coming back to this, I realize it was actually the long way around as I could have modified the data to get the desired results.

Most shading gradients are consistent in their progression, as you step through it, every step darker or lighter is the same as the previous. This was no good for my data and instead I believed a gradient that followed a logistic pattern would be more beneficial to look at my data through. This logistic gradient would have larger jumps in darkening early on and more subtle jumps later.

Get Sam Stack’s stories in your inbox

Join Medium for free to get updates from this writer.

I created a function to apply this logarithmic approach to the blue values in and RGB combination to make them darken more quickly. The result is below.

Press enter or click to view image in full size

As you can see the log scale gets darker much quicker and later on the changes in colors become less and less noticeable. Below is the result of applying the Log Scaled Shading to the Seaborn heatmaps cmap option.

Press enter or click to view image in full size
Heatmap with Logarithmic scale shading

This was much more useful for my intentions.

I’m an idiot…

I mentioned earlier that I’m an idiot and did this in the more complicated of the way possible. Instead of transforming the color map, I should have just transformed my data with a df.apply(np.log1p) to get the logged version of the data and then made the heatmap with that, which resulted in the below.

Press enter or click to view image in full size
Heatmap made with taking the Log of the original values.

Ethical Considerations

Its an important note that in this post I am adjusting the way the data is perceived from how it truly exists. In this situation my intent is not to fool the audience or exaggerate signal, it is just a means for me to observe the elements of the data I am interested in to a better degree. I would not use or recommend using these tactics in a presentation environment without explicitly stating the transformation, the reasoning and what was meant to be observed as a result.

Seaborn’s Color Map Options

If you’re interesting in seaing all of Seaborn’s color map options, I made a repo showing all of them.

--

--