Member-only story

Plotting a World Map with Country Borders

Python Coding
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 as gpd. geopandas is a Python library for working with geospatial data. It extends the functionality of pandas to handle spatial data by providing tools for reading, manipulating, and visualizing data with geometric attributes.
  • matplotlib.pyplot is imported as plt. This library is used to create visualizations, including plots, charts, and maps. Here, it’s used to display the map generated by geopandas.
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…

--

--

Python Coding
Python Coding

Written by Python Coding

Learn python tips and tricks with code I Share your knowledge with us to help society. Python Quiz: https://www.clcoding.com/p/quiz-questions.html

No responses yet