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.
pip3 install --upgrade pip
Step 5: Verify the pip version install using the following command.
Use pip package as shown below:
pip3 install numpy
pip3 install Pyglet
pip3 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.
1 2 3 4 5 6
import geoplotlib from geoplotlib.utils import read_csv data = read_csv("C:\\Users\\Omotayo\\Desktop\\nigeria_cities.csv") #replace path with your file path geoplotlib.dot(data,point_size=3) geoplotlib.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.
1 2 3 4 5 6
import geoplotlib from geoplotlib.utils import read_csv data = read_csv("C:\\Users\\Omotayo\\Desktop\\flight.csv") #replace path with your file path geoplotlib.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) geoplotlib.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.