Geoplotlib is an open-source Python toolbox for visualizing geographical data. It supports the development of hardware-accelerated interactive visualizations in pure Python and provides implementations of dot maps, kernel density estimation, spatial graphs, Voronoi tesselation, shapefiles, and many more common spatial visualizations.
Geoplotlib can be used to make a variety of maps, such as equivalent area maps, heat maps, and point density maps. There are also several extended modules:
The diagram below shows an overview of the geoplotlib architecture, which was built on top of numpy, scipy, and OpenGL/pyglet.
In this guide, you'll learn how to build a geoplot with geoplotlib on Windows Operating System. We will start by installing the required packages for geoplotlib.
Installing Pip on Windows operating system can be a little bit tricky, but it is also very simple.
Step 1: Download and install the Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017, and 2019 using the link below.
Step 2: Enable long paths on your Windows operating system by hitting the Windows key, typing
gpedit.msc, and pressing Enter.
Local Computer Policy >
Computer Configuration >
Administrative Templates >
Double click the Enable NTFS long paths option, as shown below, and enable it.
Select the Enable radio button, as shown below.
Click OK to see the enabled page, as shown below.
Step 3a: Download and install Python 3 using the link below.
Step 3b: Check Add Python to PATH and click on Install Now.
Step 4: Verify the pip version with the command as shown below on command prompt, and if the version is 19 or higher, skip step 5. Otherwise, proceed.
Step 5: Upgrade to the latest version using the command below.
1pip3 install --upgrade pip
Step 5: Verify the pip version install using the following command.
Use pip package as shown below:
1pip3 install numpy
1pip3 install Pyglet
1pip3 install geoplotlib
Step 1: Download a simple geospatial dataset (containing latitude and longitude values) from LatLong.net.
Step 2: Highlight the table, copy and paste it into Excel, and save it as a CSV file.
Step 3: Copy or type the script below in your Python editor.
1import geoplotlib 2from geoplotlib.utils import read_csv 3 4data = read_csv("C:\\Users\\Omotayo\\Desktop\\nigeria_cities.csv") #replace path with your file path 5geoplotlib.dot(data,point_size=3) 6geoplotlib.show()
You've created a dot density map of cities in Nigeria.
Step 1: Download a simple geospatial dataset (containing latitude and longitude values) from andrea-cuttone on github brain.
Step 2: Copy or type the script below in your Python editor.
1import geoplotlib 2from geoplotlib.utils import read_csv 3 4data = read_csv("C:\\Users\\Omotayo\\Desktop\\flight.csv") #replace path with your file path 5geoplotlib.graph(data, src_lat='lat_departure', src_lon='lon_departure', dest_lat='lat_arrival', dest_lon='lon_arrival', color='hot_r', alpha=16, linewidth=2) 6geoplotlib.show()
You've created a spatial graph of airport locations, where each node represents an airport and each edge represent a flight connection.
In this guide, you learned how to use geoplotlib, a Python toolbox for generating geopraphical visualizations. We demonstrated how geoplotlib is used for dot density maps and spatial graphs. Geoplotlib is a powerful API that can be used for various types of map representations, such as voronio tesselation, delaunay triangulation, markers, and so on using the various modules highlighted in the introduction section.
This guide won't be complete if we don't give special thanks to the creators of the geoplotlib package, as well as Andrea Cuttone, Sune Lehmann, Jakob Eg Larsen, and LatLong.net.
To learn more, please visit Andrea Cuttone's github page.