Python plot trajectories density

Viewed 970

I am working on trajectories and I would like to plot a "density map" of the trajectories.

Here is a sample of a code with only 4 trajectories which I can use to plot trajectories on a base-map for example.

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.basemap import Basemap

map = Basemap(projection="merc",resolution="i",llcrnrlat=25,urcrnrlat=65,llcrnrlon=-100,urcrnrlon=-55) 
map.bluemarble()

dico={}
dico["traj1"]=[[27.5, -86.5], [35.5, -85.0], [40.5, -84.0], [45.5, -82.5], [46.0, -81.5], [47.5, -79.5], [48.5, -78.0], [49.5, -76.0], [51.0, -75.0]]
dico["traj2"]=[[27.5, -88.5], [35.5, -92.5], [40.5, -97.5], [45.5, -93.5], [48.5, -90.0], [53.5, -95.0], [57.0, -100.0], [55.5, -102.0], [53.5, -101.5]]
dico["traj3"]=[[27.5, -88.5], [33.5, -88.0], [34.0, -86.5], [34.0, -84.5], [34.0, -82.0], [34.0, -80.0], [34.0, -78.5], [34.0, -77.5], [32.5, -77.0]]
dico["traj4"]=[[27.5, -86.5], [35.5, -82.5], [40.5, -77.5], [45.5, -78.5], [47.5, -77.5], [47.0, -76.0], [46.0, -73.0], [45.5, -70.5], [45.5, -66.5]]

for i in range(0,4) :
    lons_values=[item[1] for item in dico["traj"+str(i+1)]]
    lats_values=[item[0] for item in dico["traj"+str(i+1)]]

    z,t = map(lons_values, lats_values)
    map.plot(z, t, linewidth=3.5,color=np.random.rand(3,1))

Does anyone know how to draw an envelop with contours describing the main pattern of the trajectories? For example if I have 100 trajectories I would like to visualize different contours for which the color indicates the "concentration" of trajectories in this path.

If we consider that every point of a trajectory corresponds to one time step, if an information about the time step (like contour lines crossing each point of time step t) could also be present on the map, it would be great (so that information about time and space are conserved).

1 Answers
Related