Situational Shading
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.
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.
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.
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.
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.







