Learn how to set scales in Altair.

Scales map data values to visual properties. In Altair, we can determine the scale of an encoding channel by passing the scale parameter to it.

How to use scales in Altair

To scale a specific encoding channel, set the scale parameter as follows.

Consider the following example that uses the competition dataset and shows the number of gold medals won by each country in a fake competition. The chart shows countries belonging to the same continent with the same color. We use scale=alt.Scale(domain=continents, range=colors) in the color encoding to specify the range and domain of the color scale.

Get hands-on with 1200+ tech skills courses.