Note
Go to the end to download the full example code.
Average direction for each grid cell
See the flow between grid cells.
import traja
df = traja.generate(seed=0)
Average Flow (3D)
Flow can be plotted by specifying the kind parameter of traja.plotting.plot_flow()
or by calling the respective functions.
import traja
traja.plotting.plot_surface(df, bins=32)

<Axes3D: xlabel='m', ylabel='m'>
Quiver
Quiver plot Additional arguments can be specified as a dictionary to quiverplot_kws.
traja.plotting.plot_quiver(df, bins=32)

<Axes: xlabel='m', ylabel='m'>
Contour
Parameters filled and quiver are both enabled by default and can be disabled. Additional arguments can be specified as a dictionary to contourplot_kws.
traja.plotting.plot_contour(df, filled=False, quiver=False, bins=32)

<Axes: xlabel='m', ylabel='m'>
Contour (Filled)
traja.plotting.plot_contour(df, bins=32, contourfplot_kws={"cmap": "coolwarm"})

<Axes: xlabel='m', ylabel='m'>
Stream
‘cmap’ can be specified, eg, ‘coolwarm’, ‘viridis’, etc. Additional arguments can be specified as a dictionary to ‘streamplot_kws’.
traja.plotting.plot_stream(df, cmap="jet", bins=32)

<Axes: xlabel='m', ylabel='m'>
Polar bar
traja.plotting.polar_bar(df)

/home/docs/checkouts/readthedocs.org/user_builds/traja/checkouts/latest/traja/trajectory.py:1230: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
trj.loc[mask, "heading"] = angle[mask]
/home/docs/checkouts/readthedocs.org/user_builds/traja/checkouts/latest/traja/plotting.py:1228: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
trj["turn_angle"] = feature_series
/home/docs/checkouts/readthedocs.org/user_builds/traja/checkouts/latest/traja/frame.py:162: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self[name] = value
/home/docs/checkouts/readthedocs.org/user_builds/traja/checkouts/latest/traja/plotting.py:1191: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
ax.set_xticklabels(["0", "45", "90", "135", "180", "-135", "-90", "-45"])
<PolarAxes: >
Polar bar (histogram)
traja.plotting.polar_bar(df, overlap=False)

/home/docs/checkouts/readthedocs.org/user_builds/traja/checkouts/latest/traja/trajectory.py:1230: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
trj.loc[mask, "heading"] = angle[mask]
/home/docs/checkouts/readthedocs.org/user_builds/traja/checkouts/latest/traja/plotting.py:1228: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
trj["turn_angle"] = feature_series
/home/docs/checkouts/readthedocs.org/user_builds/traja/checkouts/latest/traja/frame.py:162: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
self[name] = value
/home/docs/checkouts/readthedocs.org/user_builds/traja/checkouts/latest/traja/plotting.py:1191: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator.
ax.set_xticklabels(["0", "45", "90", "135", "180", "-135", "-90", "-45"])
<PolarAxes: >
Total running time of the script: (0 minutes 2.860 seconds)