Last Updated : 24 Jul, 2025
GeoPandas is a powerful open-source Python library that extends the functionality of Pandas to support spatial/geographic operations. It brings the simplicity of pandas to geospatial data and makes it easy to visualize and analyze geographical datasets with minimal code. GeoPandas combines several libraries:
You can install the required libraries using pip:
pip install geopandas
pip install matplotlib
pip install numpy
pip install pandas
Alternatively, platforms like Google Colab or Jupyter Notebook often have many of these pre-installed or allow for quick installation within cells.
Getting StartedStep 1: Import Required Modules
Python
import pandas as pd
import geopandas as gpd
import numpy as np
import matplotlib.pyplot as plt
Step 2: Load Sample GeoSpatial Dataset
GeoPandas provides sample datasets for practice. One of the most commonly used is the world map dataset, which includes country-level geographic and economic information.
Python
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
world.head()
Output
world.head()Explanation: This loads the built-in world dataset containing country-level geometries and attributes like population, GDP and continent. head() displays the first few records.
Plotting the World MapGeoPandas makes geospatial plotting simple. Using the built-in world dataset and the .plot() method, we can quickly visualize country boundaries:
Python
world.plot()
plt.title("World Map")
plt.show()
Output
World PlotExplanation: A simple .plot() call visualizes country boundaries. Adding a title with Matplotlib improves clarity.
Analyze and Filter DatasetTo focus on a specific region, we can filter the dataset. Here, we extract only Asian countries and visualize their GDP estimates (gdp_md_est) using a red color gradient:
Python
world_asia = world[world.continent == "Asia"]
world_asia.plot(column='gdp_md_est', cmap='Reds', legend=True)
plt.title("GDP of Countries in Asia")
plt.show()
GDP of Countries in Asia
Explanation: This filters the dataset to only include Asian countries, then plots them using a red color gradient based on GDP (gdp_md_est). The legend=True adds a scale.
Visualizing World Population EstimatesTo visualize population estimates (pop_est), we can use the cmap property to apply color gradients—lighter shades indicate lower values, darker shades indicate higher ones:
Python
world.plot(column ='pop_est')
Output:
Population EstimateExplanation: This uses the pop_est column to apply a color gradient—automatically mapping population estimates to shades of blue (default).
Enhanced Visualization with Axes and StylingThe default population plot lacks visual clarity. We improve it by:
fig, ax = plt.subplots(1, figsize =(16, 8))
world.plot(ax = ax, color ='black')
world.plot(ax = ax, column ='pop_est', cmap ='Reds')
Output:
World PopulationExplanation: First, a larger figure is created. A base black world map provides contrast. Then, population data is overlaid using a red color map (cmap='Reds') to improve visual clarity.
Add a Color Bar Using Axes DividerTo improve map readability, we add a color bar to show the data scale. Using the facecolor parameter (e.g., light blue) enhances visual contrast. We then apply make_axes_locatable from mpl_toolkits.axes_grid1 to create a side space for the color bar.
Python
from mpl_toolkits.axes_grid1 import make_axes_locatable
fig, ax = plt.subplots(1, figsize =(16, 8),
facecolor ='lightblue')
world.plot(ax = ax, color ='black')
world.plot(ax = ax, column ='pop_est', cmap ='Reds',
edgecolors ='grey')
# axis for the color bar
div = make_axes_locatable(ax)
cax = div.append_axes("right", size ="3 %", pad = 0.05)
# color bar
vmax = world.pop_est.max()
mappable = plt.cm.ScalarMappable(cmap ='Reds',
norm = plt.Normalize(vmin = 0, vmax = vmax))
cbar = fig.colorbar(mappable, cax)
ax.axis('off')
plt.show()
Output:
World PopulationExplanation: This enhances the map with a clear color bar indicating population ranges. make_axes_locatable
creates space for it, while a light blue background improves aesthetics. Red shades represent population estimates, with a legend showing intensity levels.
Plotting Geospatial Data using GeoPandas
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4