This tutorial has been updated and moved to http://introtopython.org/visualization_earthquakes.html.
If you are a python programmer, you have probably heard of matplotlib. It’s a wonderful tool for data visualization work, but it can be confusing to work with at first. This tutorial introduces the Basemap library, which can be used to create maps and plot geographical datasets.
The main goal of this tutorial is to help you get comfortable making maps of geographical data. If you follow along with the tutorial, you will end up making this map:
It takes fewer than 50 lines of code to generate this map from a raw dataset! This tutorial concludes with a listing of datasets to explore.
- Installing matplotlib and Basemap
- This is the only OS-specific post. If you are using OSX or another linux distribution, you can probably adapt the installation instructions to your own setup.
- Installing from Ubuntu’s package manager
- Installing from source on Ubuntu
- Making a simple map
- Create a map of the world, and modify the look and feel of the map
- Zoom in on a certain part of the world
- Plotting points on a simple map
- Plot single points on your map, and plot sets of points
- Add labels to all or some of your points
- Plotting global earthquake activity
- Parse a geographical CSV data file for the information we want
- Plot the data on our map, and customize the appearance of our data
- Interesting datasets to explore
- A short, annotated list of data sets to explore with your new mapping skills
One of my goals in writing this tutorial is to help high school students apply their interest in programming to their core academic subjects. If you are a high school student, please consider using this technique to create a visualization for one of your classes, that none of your non-programming peers could even consider making. You will probably impress your teacher, you will get to use programming in one of your required classes, and you will certainly learn some interesting things in the process.
Whatever your motivations are for learning about mapping, I hope this tutorial helps you understand how to use matplotlib’s Basemap package a little better. Thank you to the folks who have made these resources available to all of us!