I wish to visualize geographical data in Python, without using ArcGIS/ArcPy, and make a map.

On the internet I found how to make a thematic map using Python:

Here is some code that I tried:

import shpUtils
import matplotlib.pyplot as plt

shpRecords = shpUtils.loadShapefile('C:\\Users\\shapefile.shp')

for i in range(0,len(shpRecords)):
    x = []
    y = []
    for j in range(0,len(shpRecords[i]['shp_data']['parts'][0]['points'])):

    tempx = float(shpRecords[i]['shp_data']['parts'][0]['points'][j]['x'])
    tempy = float(shpRecords[i]['shp_data']['parts'][0]['points'][j]['y'])


However, when I run this, it gives me random colors.

If I want to visualise one certain column of my shapefile, how can I implement this using similar code?

This is very unclear in the link provided above where he only discusses the usage of colors...

Would I perhaps need extra modules to accomplish this, like descartes and PySAL?

4 Answers 4


I do not know ArcPy, but I work with shapefiles and raster in Python for years

  1. For processing shapefiles in Python, there are many modules like osgeo/ogr, Fiona, Pysal or Pyshp (shpUtils is one of them and not the most used), and others, see Pypi: GIS and examples on gis.stackexchange and many examples on the Web (not only in English). Most of them are much older than ArcPy (or arcgisscripting)...
  2. for processing raster you can use osgeo/gdal, the standard
  3. For processing geospatial geometries, there is shapely
  4. For plotting the geometries you can use matplotlib and possibly descartes, "extension" of matplotlib for areas, but also many, many other modules, see Pypi: Plotting and modules like mayavi for 3D representation (matplotlib also)
  5. There are also modules like mapnik which give you directly the possibilities of 1) read a shapefile and 4) plotting with the module Pycairo.

After that, it's like a GIS:

  • you use the modules 1) to open, save the shapefiles and carry out the treatments with other modules like numpy or scipy, if you want.
  • you can use shapely for manipulation and analysis of the geometric objects (buffer, etc.).
  • you can use matplotlib to plot the geometries, but matplotlib do not know what you want to plot. It is your work with modules 1) or 3) to specify what to plot (attributes, etc,.) and how.

If I want to visualise one certain column of my shapefile, how can I implement this in the code?

So, you must learn matplotib and the other modules. You have to learn ArcPy, it's the same...(there are lots of excellent tutorials on the web, especially for matplolib, and it's easier that ArcPy because it is pure Python).

Some examples with Python only

enter image description here

Geological map (polygon shapefile) with colors based on an attribute

enter image description here

3D Points (PointZ shapefile) with color based on an attribute

enter image description here

3D points (Point shapefile with z as attribute) and 3D line (PolyLineZ shapefile) on a DEM, and on a raster draped onto the DEM surface.

enter image description here

Topographic profile with z values and colors based on attributes (geological formations = Cross section) of the original shapefile (Polyline shapefile)

enter image description here

DEM (GeoTIFF) with the module Mayavi2

enter image description here

DEM (ESRI ascii grid, .asc) and Point shapefiles (with z as attribute) with the module visvis

enter image description here

Boreholes (3D buffer of a polylineZ with colors based on an attribute (geological formations), with a grid surface calculated with the modules numpy and matplotlib from a points shapefile (with z as an attribute), visualized with the module visvis


I've had similar problems where I want to visualize shapefiles quickly, and I've always found the Matplotlib way quite a lengthy way to accomplish such a small task. Instead I developed the "Python Geographic Visualizer" module, or GeoVis for short. Update: v0.2.0 is now out with lots of new functionality.

With it visualizing shapefiles couldn't be easier:

import geovis

Voila, you map pops up as an image in a Tkinter window and you can also save the map to an image file. Styling, coloring, and adding multiple layers to a map is also possible, and in the newest version you can also classify based on attributes and zoom in to a particular region. In the map below geovis loaded and categorically colored all the world's GADM provinces in about 5 minutes. You can download GeoVis from here, where you can also read more about how to use it.

enter image description here

The aim is on easy installation as much as ease-of-use, so GeoVis can be used by anyone who has Python and does not require any other modules since it can use the builtin Tkinter Canvas as a renderer. But it is highly recommended that you have or get either Aggdraw, PIL, or PyCairo, which can also be used as renderers and are much faster and higher quality.

Backdraw is your shapefile has to be unprojected with lat/long coordinate system--it doesn't yet handle projections or transformations.


I came across a number of tutorials dealing with this topic that I wanted to share:

You might also consider using R: How to create an attractive choropleth map in R?


In 2019 the simplest way to make a thematic map from a shapefile in python, is geopandas.

An example from the documentation: http://geopandas.org/mapping.html

import geopandas
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
world['gdp_per_cap'] = world.gdp_md_est / world.pop_est

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.