Visualization
- animate(model, fig, axs, plot, steps=None, seed=None, skip=0, fargs=(), **kwargs)[source]
Returns an animation of the model simulation, using
matplotlib.animation.FuncAnimation()
.- Parameters
model (Model) – The model instance.
fig (matplotlib.figure.Figure) – Figure for the animation.
axs (matplotlib.axes.Axes or list) – Axis or list of axis of the figure.
plot (function) – Function that takes the arguments model, axs, *fargs and creates the desired plots on each axis at each time-step.
steps (int, optional) – Number of (additional) steps for the simulation to run. If passed, the parameter ‘Model.p.steps’ will be ignored. The simulation can still be stopped with :func:’Model.stop’. If there is no step-limit through either this argument or the parameter ‘Model.p.steps’, the animation will stop at t=10000.
seed (int, optional) – Seed for the models random number generators. If none is given, the parameter ‘Model.p.seed’ will be used. If there is no such parameter, a random seed will be used.
skip (int, optional) – Steps to skip before the animation starts (default 0).
fargs (tuple, optional) – Forwarded fo the plot function.
**kwargs – Forwarded to
matplotlib.animation.FuncAnimation()
.
Examples
An animation can be generated as follows:
def my_plot(model, ax): pass # Call pyplot functions here fig, ax = plt.subplots() my_model = MyModel(parameters) animation = ap.animate(my_model, fig, ax, my_plot)
One way to display the resulting animation object in Jupyter:
from IPython.display import HTML HTML(animation.to_jshtml())
- gridplot(grid, color_dict=None, convert=False, ax=None, **kwargs)[source]
Visualizes values on a two-dimensional grid with
matplotlib.pyplot.imshow()
.- Parameters
grid (numpy.array) – Two-dimensional array with values. numpy.nan values will be plotted as empty patches.
color_dict (dict, optional) – Dictionary that translates each value in grid to a color specification. If there is an entry None, it will be used for all NaN values.
convert (bool, optional) – Convert values to rgba vectors, using
matplotlib.colors.to_rgba()
(default False).ax (matplotlib.pyplot.axis, optional) – Axis to be used for plot.
**kwargs – Forwarded to
matplotlib.pyplot.imshow()
.
- Returns