Mapping and Setting Colors with Scatterplots
Get familiar with managing the colors of scatterplots using Plotly.
Let’s now explore the different options that we have to manage color.
Colors are extremely important in conveying and expressing information about our charts. We’ll focus on colors for two types of variables—discrete and continuous. We will also tackle two ways of using colors in our charts—mapping variables to colors and manually setting our colors.
We start by exploring the differences between the two types of variables.
Discrete and continuous variables
Simply speaking, continuous variables are the ones that can take an infinite number of possible values in a certain range of numbers. For example, population is a number that can take any value based on the number of people living in a certain country. Continuous variables are typically numbers (integers or real numbers). Height, weight, and speed are other examples as well.
Discrete variables, on the other hand, are variables that can take the value of any one of a limited set of items. Most importantly, discrete variables can’t take values in between the items. Countries are one example. A country can either be country A or country B but can’t be $10\%$ A and $90\%$ B. Discrete variables are typically text variables and usually have a relatively small number of unique items.
The way we use color to express the nature of our variables is as follows:

Continuous variables: For continuous variables, we use a color scale that takes on colors that gradually change between two or more colors as the values they represent change. For example, if our color scale starts as white for the lowest value and ends up as blue at the highest value, all values in between would take on varying shades of white and blue. A marker that has a color that contains more blue than white means that its value is closer to the maximum value of that variable and vice versa. We will try this shortly.

Discrete variables: These are distinct items, and the colors we use for them need to be as distinct from each other as possible, especially the ones that appear next to each other. Examples will make this clear, and we will start with continuous variables.
Using color with continuous variables
Using the same metric we started with, we want to take an arbitrary year and plot the indicator value for each of the countries. We already know how to do this. We now want to add a new dimension to our chart. We want to use color to show another value, for example, population. This will allow us to see whether there is any correlation between population and the metric we are plotting (poverty at $1.90 in this case). Let’s prepare our variables and data.
Get handson with 1200+ tech skills courses.