GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • PYTHON CHARTS
  • matplotlib
  • seaborn
  • plotly
  • pandas
  • colors
  • COLORS
  • COLOR PALETTES
  • R CODER
  • R CHARTS
  • Contact
  • Español

This view

  • Original page
  • New address

GeezerVison is showing python-charts.com — Static map in Python with geopandas

Search for a graph

HOME SPATIAL STATIC MAP GEOPANDAS

Static map in Python with geopandas

Static map in Python with geopandas

Unlike the interactive choropleth map built with plotly, geopandas renders a static map through matplotlib, which is often enough for a report or a document. Read any shapefile or geojson with read_file and call .plot() on the resulting GeoDataFrame.

import geopandas
import matplotlib.pyplot as plt

# Shapefile with the Spanish autonomous communities
shp = geopandas.read_file("https://raw.githubusercontent.com/R-CoderDotCom/data/main/shapefile_spain/spain.zip")

shp.plot()

# plt.show()

Static map in Python with geopandas

Choropleth map

The shapefile used above already includes an unemp_rate column. Pass its name to the column argument, together with cmap and legend = True, to color each region by its value and add a colorbar.

import geopandas
import matplotlib.pyplot as plt

shp = geopandas.read_file("https://raw.githubusercontent.com/R-CoderDotCom/data/main/shapefile_spain/spain.zip")

shp.plot(column = "unemp_rate", cmap = "viridis", legend = True)

# plt.show()

Choropleth map in Python with geopandas

Border color

Add a border around each region with edgecolor and linewidth.

import geopandas
import matplotlib.pyplot as plt

shp = geopandas.read_file("https://raw.githubusercontent.com/R-CoderDotCom/data/main/shapefile_spain/spain.zip")

shp.plot(column = "unemp_rate", cmap = "viridis", legend = True,
        edgecolor = "white", linewidth = 0.5)

# plt.show()

Border color of a static map in geopandas

Removing the axis

plot returns a regular matplotlib Axes, so its coordinate axis (latitude and longitude) can be hidden the usual way with set_axis_off.

import geopandas
import matplotlib.pyplot as plt

shp = geopandas.read_file("https://raw.githubusercontent.com/R-CoderDotCom/data/main/shapefile_spain/spain.zip")

ax = shp.plot(column = "unemp_rate", cmap = "viridis", legend = True)
ax.set_axis_off()

# plt.show()

Static map without axis in geopandas

Title

Since ax is a regular matplotlib Axes, add a title with set_title.

import geopandas
import matplotlib.pyplot as plt

shp = geopandas.read_file("https://raw.githubusercontent.com/R-CoderDotCom/data/main/shapefile_spain/spain.zip")

ax = shp.plot(column = "unemp_rate", cmap = "viridis", legend = True)
ax.set_axis_off()
ax.set_title("Unemployment rate by region")

# plt.show()

Title of a static map in geopandas

R CODER website
Better Data Visualizations

Better Data Visualizations

A Guide for Scholars, Researchers, and Wonks

Buy on Amazon
Storytelling with Data

Storytelling with Data

A Data Visualization Guide for Business Professionals

Buy on Amazon

See also

Bubble map in plotly

Bubble map in plotly

Dorling cartogram in Python with matplotlib

Dorling cartogram in Python with matplotlib

Interactive leaflet maps in Python with folium

Interactive leaflet maps in Python with folium

Scatter map in plotly with scatter_geo and scatter_map

Scatter map in plotly with scatter_geo and scatter_map

Choropleth map in Python with geopandas

Choropleth map in Python with geopandas

Heat map on a map (spatial heat map) in plotly

Heat map on a map (spatial heat map) in plotly

Hexbin map in Python with geopandas

Hexbin map in Python with geopandas

Choropleth maps in plotly

Choropleth maps in plotly

Connection map in Python with matplotlib

Connection map in Python with matplotlib

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.