course content

Course Content

Visualization in Python with matplotlib

Further GroupingFurther Grouping

In the previous chapter, we colored the points in accordance with the continent. This was the categorical variable (which means it can take on one of a limited, usually fixed, number of possible values). But what if we want to use colors in accordance with a numeric variable? In that case, most likely, we are talking about the continuous variable (can take on an uncountable set of values). A popular solution is using colormaps (I assume you heard about heatmaps). With this approach, points are colored more intense the color is, the greater value (for example).

Let's return to our traditional example. To use colormap we need to follow the next steps:

  1. Assign ax.scatter() to some variable, and additionally pass cmap as a parameter (this one is colormap; possible values are in the documentation).
  2. Apply the .colorbar function to the Figure object (usually fig), passing the newly created variable (step 1) as a parameter.

Everything was clear?

Section 3. Chapter 9