Customizing the Folium Choropleth
00:32 First, let’s update the color palette of our choropleth for the population of each New York City borough. Folium defaults to a sequential blue palette for choropleth layers, but you can choose any Brewer color palette option.
Let’s use the Yellow-Orange-Red sequential color palette to further emphasize boroughs with larger populations. To switch your choropleth’s color palette, just pass the name of that palette to the
A value of
0 will make these regions fully transparent, while a value of
1 makes each region fully opaque. And likewise, you can also adjust the transparency of the border lines of each region with
The populations here range between zero and three million, so let’s make the bins of this choropleth evenly spaced at every half million. Just pass a list of where each bin starts and stops to the
Just check the Folium documentation anytime you need a refresher. In a Jupyter Notebook, you can click within the
Choropleth parentheses, hold the Shift key, and press Tab to bring up the signature and docstring.
03:31 Before concluding this lesson, let’s explore one more type of customization for Folium maps: adding markers for places of interest. Say you’d like to indicate where sites like the Empire State Building and the Statue of Liberty are located, and you currently have those sites in a dictionary where the names are the keys and the latitude/longitude coordinates are the values.
Folium also allows you to add tooltips to your markers so that text appears when users hover over them. In this case, let’s set
tooltip equal to
site, which will represent the string name of each site as we loop over them.
Now, you’ll be able to recognize this marker as the Empire State Building and this one as Central Park. Finally, you also have the option to further customize your markers by passing a specific Folium icon to the
05:13 Nice job. In this lesson, you learned all about styling your choropleth, including its color palette and color bar. You also added markers with tooltips to your map to indicate points of interest.
Become a Member to join the conversation.