1. Continuous color palettes
Now that we've talked about the basics of color in visualization let's dig deeper and look at using color to represent continuous data.
2. Continuous data
Continuous data are measurements that have order and a large number of possible values. For instance, in our pollution data, all pollutant values are continuous whereas variables like city are not, as there is no inherent order to cities themselves.
3. Seaborn's continuous palettes
We've already seen how we can encode values using color in Seaborn by mapping the variable to the hue argument. To choose optimal palettes for our plots, we're going to need to customize our palettes.
Luckily Seaborn makes this easy by bundling helpful color palette functions along with the function palplot() to quickly look at a given palette.
Here we make a palette that maps low values to light blues and high values to a darker blues by using Seaborn's light_palette() function.
We can also use the complementary palette function dark_palette() do the same but with dark representing low values and red being our high values.
4. Color is less precise
One thing to keep in mind while making your palettes for continuous-color encodings is that color will provide a lower precision mapping of your data than using a physical mapping like the length of a bar. With a bar chart, you can simply find the top of the bar on the axis directly whereas with color you have to compare to, a usually far away, legend.
When you are building your visualization ask yourself if the highest precision possible is needed, and if it is, avoid continuous color scales.
5. Keep it simple
If you are going to use color, a way of keeping your continuous palettes as precise as possible is to keep them simple. For continuous data go from a null color such as white or black to some color of interest in a linear path.
We can use the same light palette we just made to build a heat map of O3 levels using Seaborn's heatmap() function. The plot clearly shows patterns across the year as bands of darker or lighter colors.
6. Keep it simple
Compare this with the unfortunately common 'jet' palette version, where patterns are almost impossible to see.
7. Be aware of color blindness
One beneficial side-effect of keeping palettes simple is it makes them better for people who have color-blindness. The most common type of color blindness is red-green color blindness which makes it impossible for one to distinguish between similar values of red and green. By keeping palettes a single color and ramping up the intensity of that color, you can help keep your visualizations accessible to more viewers.
8. Encoding neutral values
One instance where you will break this single color rule is when your data has a natural center point.
In these cases, it makes sense to use something called a diverging palette. Luckily Seaborn has the convenient diverging_palette() function for this purpose.
For instance, say we don't care about the exact pollution values in our data but how a city compares to the average. Here, we the plotted values have a conceptual middle: the value of zero standard deviations away from the average value.
9. Be aware of contexts
Another area you must be careful using color in visualization is with the concept of the 'null' color. In the heatmap example from earlier, we encoded the null or zero value as white.
In this scatter plot we again use the light_palette() function to map low values to white and high values to orangered.
10. Be aware of contexts
Sometimes however this light equals low mapping doesn't work. For instance, if your plot is on a dark background, the reader will often subconsciously infer lighter colors with higher values. Even if your legend points out the correct order, you should assume your reader won't look at it.
Luckily we can adjust the color palette quickly by swapping in dark_palette() in place of light_palette().
11. Let's continue in the exercises
Let's put some of these techniques to work in the exercises.