#!/usr/bin/env python # coding: utf-8 # # Analyzing Spatial Trajectories with Traja # Full documentation is available at [traja.readthedocs.io](http://traja.readthedocs.io). # In[1]: import traja # In[3]: # Create sample random walk df = traja.generate() # Visualize x and y values with built-in pandas methods df.plot() # ## Plot Trajectory # ### Plot trajectory with traja accessor method (`.traja.plot()`) # In[6]: fig = df.traja.plot() # ### Visualize distribution of angles and turn-angles # In[9]: df.traja.calc_angle().hist() # w.r.t x-axis # In[19]: df.traja.calc_turn_angle().hist() # deviation from strait ahead # ### Visualize flow between grid units # In[15]: for kind in ['stream', 'quiver', 'contourf']: fig = df.traja.plot_flow(kind=kind) # ### Visualize distribution of turn angles over time # In[17]: df.traja.calc_turn_angle().plot() # In[29]: for log in [True, False]: for bins in [8, 32]: print(f"Bins: {bins}") df.traja.trip_grid(bins=bins, log=log) # ### Plot polar bar chart showing turn preference # In[31]: traja.plotting.polar_bar(df) # In[33]: # Show non-overlapping histogram traja.plotting.polar_bar(df, overlap=False) # ## Resample Trajectory # In[36]: # Resample to arbitrary step length (here, 20 meters) fig = df.traja.rediscretize(R=20).traja.plot() # In[40]: # Resample to arbitrary time (here, 1 second) fig = df.traja.resample_time(step_time='1s').traja.plot()