Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Creating a Map

00:00 Now that you know more about what Folium is, let’s use it to make a map.

00:06 In this course, you’ll create Folium maps from within a Jupyter Notebook. This allows you to immediately display your maps in your notebook. You can make Folium maps with Python scripts instead.

00:18 You would just need to save and then open each map in a browser to interact with it. You’ll learn how to save Folium maps at the end of this lesson. Once you’ve installed Folium, you can use its codebase by running import folium.

00:33 And now to make your first map, just type folium.Map(). Amazingly, Folium has already provided you with an interactive map of the world. You can zoom in by clicking the + (plus) button and out with the - (minus) button.

00:50 You can explore different regions by dragging the map with your mouse, and you’ll likely also be able to zoom in and out by scrolling with your mouse. And notice how more details appear as you zoom in further and further.

01:05 You’ll be able to see bodies of water, landmarks, parks, and even some buildings. Folium also allows you to update the entire look and feel of your map by selecting from various different web tile options.

01:19 But before exploring these options in Python code, in case you’re not familiar with them, what exactly is a web map tile? A web tile represents one specific geographic area, and web tiles can be raster images or collections of vector data.

01:37 While each tile represents a specific location, web maps can combine tiles together to represent larger regions. This allows applications to run faster and smoother since only the relevant tiles associated with what the user is currently viewing need to be loaded.

01:56 Furthermore, when a user pans across the map, many of the relevant tiles will remain the same and will have been loaded already. Collections of web tiles may be styled with various themes.

02:10 For example, your map can appear in black and white or appear like a watercolor painting. Let’s go back to our Jupyter Notebook and explore some Folium web tile options.

02:22 Folium comes with web tiles created by OpenStreetMap, Stamen, and CartoDB. You’ve seen the default OpenStreetMap tiles so far, so how can you switch to one of the other styles?

02:34 Just pass the name of your selection to the tiles option. Within your map command, write tiles = and then the string "Stamen Watercolor".

02:48 This switches to Stamen’s watercolor tiles. Now you’ll see a dramatically different-looking map, but once again, this map is interactive. You can zoom in and out and pan to different parts of the world.

03:03 There are more tile options built into Folium, or you can even pass a Leaflet-style URL to a custom tile set if you’d prefer. So let’s try one more built-in choice.

03:14 Here’s "CartoDB positron". This positron-based map provides geospatial context but is otherwise quite minimal. It was specifically designed so that you can showcase your own data on top of it, so you’ll be using it to make a choropleth later on in this course.

03:34 Once you’ve made a map with Folium, you can save it as an HTML file and later render it as a website. First, let’s save this positron map as the Python variable base_map. base_map is a Folium map object, and this variable now contains your entire Folium map.

03:57 You can use the .save() method on the base_map object to save your map as an HTML. Just supply your filename, which should end in .html.

04:09 Let’s call this basemap.html. And running this command saves our map as an HTML in our current working directory. If you execute !ls, this runs the Bash list command from within your Jupyter Notebook and lists out all of the files in your current directory.

04:31 You should see that basemap.html has been saved.

04:36 And if you open it up, a new tab with your positron map will appear in your browser, and you can continue interacting with it. Nice job.

04:49 Coming up next, you’ll use options to adjust the starting properties of your Folium map, including the geographic location and zoom level, so that you can focus on a specific region of the world.

Become a Member to join the conversation.