Member-only story
Plotting a World Map with Country Borders
2 min readOct 28, 2024
pip install geopandas
import geopandas as gpd
import matplotlib.pyplot as plt
world = gpd.read_file('ne_110m_admin_0_countries.shp')
world.plot(edgecolor='black')
plt.title("World Map with Country Borders")
plt.show()
Here’s a breakdown of this code and what each part does:
import geopandas as gpd
import matplotlib.pyplot as plt
Import Libraries:
geopandas
is imported asgpd
.geopandas
is a Python library for working with geospatial data. It extends the functionality ofpandas
to handle spatial data by providing tools for reading, manipulating, and visualizing data with geometric attributes.matplotlib.pyplot
is imported asplt
. This library is used to create visualizations, including plots, charts, and maps. Here, it’s used to display the map generated bygeopandas
.
world = gpd.read_file('ne_110m_admin_0_countries.shp')
Load the Shapefile:
gpd.read_file
loads a shapefile, which is a standard format for geospatial vector data, often containing polygons (shapes) representing country borders.'ne_110m_admin_0_countries.shp'
is the path to the shapefile. This file contains data on country boundaries, so each polygon in the shapefile corresponds…