.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/plot_comparing.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_comparing.py: Comparing --------- traja allows comparing trajectories using various methods. .. GENERATED FROM PYTHON SOURCE LINES 6-11 .. code-block:: Python import traja df = traja.generate(seed=0) df.traja.plot() .. image-sg:: /gallery/images/sphx_glr_plot_comparing_001.png :alt: plot comparing :srcset: /gallery/images/sphx_glr_plot_comparing_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 12-17 Fast Dynamic Time Warping of Trajectories ========================================= Fast dynamic time warping can be performed using ``fastdtw``. Source article: `link `_. .. GENERATED FROM PYTHON SOURCE LINES 17-22 .. code-block:: Python import numpy as np rotated = traja.rotate(df, angle=np.pi / 10) rotated.traja.plot() .. image-sg:: /gallery/images/sphx_glr_plot_comparing_002.png :alt: plot comparing :srcset: /gallery/images/sphx_glr_plot_comparing_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 23-28 Compare trajectories hierarchically =================================== Hierarchical agglomerative clustering allows comparing trajectories as actograms and finding nearest neighbors. This is useful for comparing circadian rhythms, for example. .. GENERATED FROM PYTHON SOURCE LINES 28-37 .. code-block:: Python # Generate random trajectories trjs = [traja.generate(seed=i) for i in range(20)] # Calculate displacement displacements = [trj.traja.calc_displacement() for trj in trjs] traja.plot_clustermap(displacements) .. image-sg:: /gallery/images/sphx_glr_plot_comparing_003.png :alt: plot comparing :srcset: /gallery/images/sphx_glr_plot_comparing_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/traja/envs/latest/lib/python3.10/site-packages/seaborn/matrix.py:560: UserWarning: Clustering large matrix with scipy. Installing `fastcluster` may give better performance. warnings.warn(msg) .. GENERATED FROM PYTHON SOURCE LINES 38-40 Compare trajectories point-wise =============================== .. GENERATED FROM PYTHON SOURCE LINES 40-43 .. code-block:: Python dist = traja.distance_between(df.traja.xy, rotated.traja.xy) print(f"Distance between the two trajectories is {dist}") .. rst-class:: sphx-glr-script-out .. code-block:: none Distance between the two trajectories is 27254.161638114736 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.951 seconds) .. _sphx_glr_download_gallery_plot_comparing.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_comparing.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_comparing.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_comparing.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_