.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/plot_grid.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_plot_grid.py: Plotting trajectories on a grid ------------------------------- traja allows comparing trajectories using various methods. .. GENERATED FROM PYTHON SOURCE LINES 6-10 .. code-block:: Python import traja df = traja.generate(seed=0) .. GENERATED FROM PYTHON SOURCE LINES 11-14 Plot a heat map of the trajectory ================================= A heat map can be generated using :func:`~traja.trajectory.trip_grid`. .. GENERATED FROM PYTHON SOURCE LINES 14-16 .. code-block:: Python df.traja.trip_grid() .. image-sg:: /gallery/images/sphx_glr_plot_grid_001.png :alt: Time spent :srcset: /gallery/images/sphx_glr_plot_grid_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none (array([[ 0., 7., 8., 5., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], [ 0., 10., 0., 19., 9., 4., 7., 8., 9., 1., 0., 0., 0., 0., 0., 0.], [16., 17., 25., 12., 24., 7., 0., 0., 9., 3., 13., 9., 1., 0., 0., 0.], [ 9., 5., 14., 13., 19., 0., 0., 0., 11., 19., 17., 6., 9., 1., 0., 0.], [13., 15., 7., 14., 13., 0., 0., 0., 8., 14., 25., 17., 5., 8., 2., 0.], [ 3., 4., 4., 17., 11., 5., 0., 0., 7., 0., 5., 10., 9., 0., 6., 5.], [ 0., 0., 0., 4., 6., 3., 9., 0., 2., 8., 4., 13., 10., 7., 15., 3.], [ 0., 0., 0., 0., 13., 18., 20., 3., 0., 3., 13., 22., 27., 21., 19., 11.], [ 0., 0., 0., 0., 4., 11., 16., 7., 0., 9., 9., 0., 5., 20., 18., 12.], [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 6., 15., 19., 13., 2., 4., 3.]]), ) .. GENERATED FROM PYTHON SOURCE LINES 17-20 Increase the grid resolution ============================ Number of bins can be specified with the ``bins`` parameter. .. GENERATED FROM PYTHON SOURCE LINES 20-22 .. code-block:: Python df.traja.trip_grid(bins=40) .. image-sg:: /gallery/images/sphx_glr_plot_grid_002.png :alt: Time spent :srcset: /gallery/images/sphx_glr_plot_grid_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none (array([[0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], ..., [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.], [0., 0., 0., ..., 0., 0., 0.]], shape=(40, 64)), ) .. GENERATED FROM PYTHON SOURCE LINES 23-26 Convert coordinates to grid indices =================================== Number of x and y bins can be specified with the ``bins``` parameter. .. GENERATED FROM PYTHON SOURCE LINES 26-32 .. code-block:: Python from traja.trajectory import grid_coordinates grid_coords = grid_coordinates(df, bins=32) print(grid_coords.head()) .. rst-class:: sphx-glr-script-out .. code-block:: none xbin ybin 0 12 15 1 13 15 2 13 16 3 13 16 4 13 17 .. GENERATED FROM PYTHON SOURCE LINES 33-36 Transitions as Markov first-order Markov model ============================================== Probability of transitioning between cells is computed using :func:`traja.trajectory.transitions`. .. GENERATED FROM PYTHON SOURCE LINES 36-39 .. code-block:: Python transitions_matrix = traja.trajectory.transitions(df, bins=32) print(transitions_matrix[:10]) .. rst-class:: sphx-glr-script-out .. code-block:: none [[0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] ... [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.] [0. 0. 0. ... 0. 0. 0.]] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.408 seconds) .. _sphx_glr_download_gallery_plot_grid.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_grid.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_grid.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_grid.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_