Tutorial 5-C: Heatmap Trajectory Visualization

Purpose: Heatmaps give information about the density of points in a given area.

In [2]:
import tracktable.examples.tutorials.tutorial_helper as tutorial

Let’s start with a list of trajectories.

We will use the provided example data \(^1\) for this tutorial. For brevity, the function below reads our trajectories from a .traj file into a python list, as was demoed in Tutorial 4.

In [3]:
trajectories = tutorial.get_trajectory_list('tutorial-static-viz')
Loading Trajectories: 200 trajectory [00:00, 1328.12 trajectory/s]
[2025-06-09 01:09:18.731946] [0x00000001f1aadf00] [info]    Read a total of 200 trajectories.

Let’s create a list of all of the end points of the trajectories in this set.

In [4]:
points = tutorial.trajectories_to_end_points(trajectories)
In [5]:
from tracktable.render import render_map, render_heatmap
from tracktable.render.map_processing import paths
import cartopy
import matplotlib
import matplotlib.pyplot as plt

Let’s first look at static heatmap image of the end points that fall in the continental United States.

A quick note about Jupyter notebooks. Jupyter will show you the state of the figure when you exit the cell in which you created it. You cannot apply different effects in different cells. To work around this, we put all our different effects in functions, then call those functions one after another in a single cell.

In [6]:
# Set up our canvas to be a 800x600 image (8x6 inches at 100 dpi).
figure = plt.figure(dpi=100, figsize=(8, 6))

# Set up our map projection to be the continental United States.
(mymap, map_actors) = render_map.render_map(domain='terrestrial',
                                        map_name='region:conus')

# Grab default bounding box.
bbox = tutorial.get_bbox('conus', 'terrestrial')

# Render the heatmap.
render_heatmap.render_heatmap(points, # Our list of points we created above
                    backend='cartopy',
                    map_canvas=mymap,
                    bounding_box=bbox,       # Bounding box is generated from mymap
                    bin_size=1,
                    colormap='cividis')
Out[6]:
[<cartopy.mpl.geocollection.GeoQuadMesh at 0x132ca0b90>]
../_images/examples_Tutorial_05C_10_1.png

We can also render an interactive heatmap using Folium. In addition to the points in the heatmap, we can render a set of trajectories by passing the trajectories keyword argument to render_heatmap.

In [7]:
render_heatmap.render_heatmap(points, trajectories=trajectories)
Out[7]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [ ]: