GIS Data Visualization with Matplotlib: Charts, Maps, and Spatial Insights
- 2 minutes ago
- 3 min read
GIS (Geospatial Information Systems) creates large volumes of spatial data, but just having the raw coordinates or attribute tables does not often convey deep meaning. Making sense of the data through visuals transforms the complexities into simple visuals such as maps, charts, and analytical graphics, which are easier to interpret, resulting in better decision-making.
Probably the most widely used library among many available for visualising data related to science and data analysis using Python is Matplotlib. While the primary use has been for producing statistical-type graphics, it is also the base for several GIS visualisation libraries, including GeoPandas, Cartopy and Rasterio. The flexibility of Matplotlib allows developers, GIS analysts and data scientists to generate publication-ready maps and traditional analytical graphics in parallel.

Why should you use Matplotlib for GIS?
The majority of modern GIS workflows make use of Python libraries like:
Most of these libraries render images using Matplotlib. Therefore, being skilled in this library is essential for any person doing Python-based GIS analysis.
Advantages of using Matplotlib for this purpose include:
High-quality static visualizations
Total customization of maps
Great integration with other libraries such as NumPy and Pandas
Ready-to-publish graphics
Excellent compatibility with GIS libraries
Setting Up the Environment
Install the required libraries:
pip install matplotlib geopandas contextily rasterioImport the libraries:
import matplotlib.pyplot as plt
import geopandas as gpdVisualizing Vector Data
One of the simplest GIS tasks is displaying vector datasets such as:
Roads
Rivers
Administrative boundaries
Land parcels
Cities
Load a shapefile:
world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))Display the map:
fig, ax = plt.subplots(figsize=(12, 8))
world.plot(
ax=ax,
color="lightblue",
edgecolor="black"
)
ax.set_title("World Map")
plt.show()This generates a clean vector map using Matplotlib's plotting engine.
Creating Choropleth Maps
A choropleth map visualizes attribute values by coloring geographic regions.
For example, visualize population estimates:
fig, ax = plt.subplots(figsize=(12, 8))
world.plot(
column="pop_est",
cmap="viridis",
legend=True,
ax=ax
)
plt.title("Population Estimates")
plt.show()Plotting Point Data
Point datasets represent locations such as:
Schools
Hospitals
Weather stations
GPS observations
Example:
cities = gpd.read_file("cities.shp")
fig, ax = plt.subplots(figsize=(10,8))
cities. plot(
ax=ax,
color="red",
markersize=20
)
plt.show()Marker properties can be customized using:
Color
Size
Transparency
Shape
Edge color
Displaying Multiple GIS Layers
GIS maps usually contain several spatial layers.
Example:
fig, ax = plt.subplots(figsize=(12,8))
countries.plot(ax=ax, color="white", edgecolor="black")
rivers.plot(ax=ax, color="blue")
cities.plot(ax=ax, color="red", markersize=10)
plt.show()Layering improves spatial context and readability.
Visualizing Raster Data
Raster datasets include:
Temperature grids
Land cover maps
Using Rasterio:
import rasterio
with rasterio.open("dem.tif") as src:
elevation = src.read(1)
plt.imshow(
elevation,
cmap="terrain"
)
plt.colorbar(label="Elevation (m)")
plt.show()Matplotlib efficiently displays raster datasets while supporting custom color scales.
Adding Basemaps
Basemaps provide geographic context.
Using Contextily:
import contextily as ctx
ax = roads.plot(figsize=(10,10))
ctx.add_basemap(
ax,
crs=roads.crs
)
plt.show()Popular basemap providers include:
OpenStreetMap
Stamen Terrain
CartoDB Positron
Esri World Imagery
Customizing Maps
Matplotlib provides extensive styling capabilities.
Example:
fig, ax = plt.subplots(figsize=(12,8))
world.plot(
ax=ax,
edgecolor="gray",
linewidth=0.5,
color="#DCEEFF"
)
ax.set_title(
"Global Boundaries",
fontsize=18,
fontweight="bold"
)
ax.set_axis_off()
plt.show()Useful customization options include:
Titles
Fonts
Labels
Legends
Gridlines
Background colors
Figure size
Creating Heatmaps
Heatmaps help identify geographic hotspots.
Kernel density estimation (KDE) can visualize:
Crime incidents
Traffic accidents
Disease outbreaks
Population density
Example using Matplotlib:
plt.hexbin(
x_coords,
y_coords,
gridsize=50,
cmap="inferno"
)
plt.colorbar()
plt.show()Hexbin plots are especially useful for large point datasets.
Combining Statistical Charts with GIS Maps
One of Matplotlib's greatest strengths is combining spatial and statistical visualizations.
Example layout:
fig, (ax1, ax2) = plt.subplots(
1,
2,
figsize=(15,6)
)
world.plot(ax=ax1)
population.plot.bar(ax=ax2)
plt.show()This enables dashboards that combine:
Maps
Histograms
Scatter plots
Bar charts
Time series
Pie charts
Such visualizations provide both geographic and statistical perspectives.
Limitations
Matplotlib is an excellent tool for creating static visualizations but has below limitations.
Limited interactivity.
Not designed for creating web-based GIS Applications.
Performance optimizations will be necessary for large datasets.
Creating interactive dashboards with Plotly or Bokeh requires other libraries.
Libraries like Folium, Leaflet, or Plotly may be better options for creating interactive web maps.
Matplotlib is still one of the most effective tools available for visualizing GIS data in Python. Matplotlib's flexibility, customizability, and ability to integrate with libraries like GeoPandas and Rasterio make it an integral part of the modern geospatial workflow.
GIS professionals can take advantage of Matplotlib to create a large number of types of charts - ranging from simple vector maps to more advanced choropleth visualizations, rasters, and analytical dashboards- to turn raw spatial data into clear visual representations of data. By using best practices for visualization and taking advantage of the many resources available in the Matplotlib ecosystem, you can develop maps that look professionally designed while communicating spatial information that can be used to make decisions based on that information.
To learn more about Matplotlib and its geospatial capabilities, click here.
For more information or any questions regarding Matplotlib, please don't hesitate to contact us at
Email: info@geowgs84.com
USA (HQ): (720) 702–4849
(A GeoWGS84 Corp Company)
