Data Visualization
Visualize AISdb vessel tracks with the built-in web interface or with Contextily, Basemap, Cartopy, Plotly, and Kepler.gl.
This tutorial covers the visualization options available for vessel trajectories processed with AISdb, including AISdb's integrated web interface and alternative approaches built on popular Python visualization packages. Each tool comes with a working example, so you can see exactly how to turn queried AISdb tracks into a map.
Internal visualization
AISdb provides an integrated data visualization feature through the aisdb.web_interface.visualize module, which allows users to generate interactive maps displaying vessel tracks. This built-in tool is designed for simplicity and ease of use, offering customizable visualizations directly from AIS data without requiring extensive setup.
Here is an example of using the web interface module to show queried data with colors. To display vessel tracks in a single color:
import aisdb
from datetime import datetime
from aisdb.database.dbconn import SQLiteDBConn
from aisdb import DBConn, DBQuery, DomainFromPoints
import nest_asyncio
nest_asyncio.apply()
dbpath='YOUR_DATABASE.db' # Define the path to your database
# Set the start and end times for the query
start_time = datetime.strptime("2018-01-01 00:00:00", '%Y-%m-%d %H:%M:%S')
end_time = datetime.strptime("2018-01-03 00:00:00", '%Y-%m-%d %H:%M:%S')
# Define a circle with a 100km radius around the location point
domain = DomainFromPoints(points=[(-63.6, 44.6)], radial_distances=[100000])
def color_tracks(tracks):
""" Set the color of each vessel track using a color name or RGB value. """
for track in tracks:
track['color'] = 'yellow'
yield track
with aisdb.SQLiteDBConn(dbpath=dbpath) as dbconn:
qry = aisdb.DBQuery(
dbconn=dbconn, start=start_time, end=end_time,
xmin=domain.boundary['xmin'], xmax=domain.boundary['xmax'],
ymin=domain.boundary['ymin'], ymax=domain.boundary['ymax'],
callback=aisdb.database.sqlfcn_callbacks.in_time_bbox_validmmsi,
)
rowgen = qry.gen_qry()
tracks = aisdb.track_gen.TrackGen(rowgen, decimate=False)
colored_tracks = color_tracks(tracks)
# Visualization
aisdb.web_interface.visualize(
colored_tracks,
domain=domain,
visualearth=True,
open_browser=True,
)
If you want to visualize vessel tracks in different colors based on MMSI, here's an example that demonstrates how to color-code tracks for easy identification:

Alternative visualization
If you need more advanced or specialized visualization, several Python packages pair well with AISdb tracks. Contextily, Basemap, and Cartopy are solid choices for detailed 2D plots, while Plotly gives you interactive, web-based graphs. Kepler.gl is the better fit for large-scale or 3D visualizations. Each package handles the same track data differently, so pick whichever fits how you want to present and explore your AIS data.
Contextily + Matplotlib

⚠️ Basemap + Matplotlib
Note: mpl_toolkits.basemap uses numpy v1, so downgrade numpy to v1.26.4 to use Basemap, or turn to one of the other alternatives mentioned here, such as Contextily.

Cartopy

Plotly


Kepler.gl


Where to go next
Which tool to reach for depends on what you're checking. web_interface.visualize is the fastest way to eyeball a query while you're still iterating on it, since it needs no extra dependencies beyond AISdb itself. Matplotlib with Contextily or Cartopy is the right choice once you need a static figure for a report or paper, where projection control and print quality matter more than interactivity. Kepler.gl is built for the opposite case, large track sets that need to be filtered, layered, and explored interactively rather than viewed once and discarded.
Once tracks are visualized, tutorials/track-interpolation.md covers filling gaps between AIS position reports so the tracks you plot are continuous rather than jumping between sparse pings.
Last updated