Skip to content

Commit

Permalink
Add animation for plotting densities over time.
Browse files Browse the repository at this point in the history
  • Loading branch information
jswright-dstl committed Jun 21, 2022
1 parent 5a32cfb commit 00c464b
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions docs/examples/density_plot_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# %%
# Set the imports and set the start time
from datetime import datetime, timedelta
from matplotlib import pyplot as plt
from matplotlib import pyplot as plt, animation

from stonesoup.types.groundtruth import GroundTruthPath, GroundTruthState
from stonesoup.models.transition.linear import CombinedLinearGaussianTransitionModel, \
Expand Down Expand Up @@ -77,17 +77,24 @@ def generate_ground_truth_path(initial_state, num_steps=20, motion_model_noise=0
# The function allows you to pick an index of the state sequence (ground truth in this example) to
# plot. In this example we're only interested in the final state of the sequences. An index of '-1'
# is the last state in the sequence.
# The resultant plot in much more spread out
# The resultant plot is much more spread out
plotter = Plotter()
plotter.plot_density(truths, index=-1)

# %%
# Plot each state
# Plot each state over time
# -------------------------------------------------
# Plot the density at each time-step and see how the density plot evolves
plotter = Plotter()
for i in range(1, n_time_steps):
# Plot the density at each time-step and see how the density plot evolves. Define an animation
# update function.


def update(i):
plotter.ax.clear()
plotter.plot_density(truths, index=i)
plt.show(block=False)
plt.pause(0.1)
return plotter.ax


# %%
# Plot the densities over time.
plotter = Plotter()
animation.FuncAnimation(plotter.fig, update, frames=range(1, n_time_steps))

0 comments on commit 00c464b

Please sign in to comment.