Plotting¶
These functions are for visualizing simulation results.
Trajectory¶
- example_gni_project.plot_trajectory(simulation: SimulationResult, filename=None)¶
Plot the entire discrete trajectory. The figure contains one line plot for every component of the state space.
- Parameters:
simulation (SimulationResult) –
filename (str) – If a filename (path) is provided, the plot is saved.
Phase portrait¶
- example_gni_project.plot_phase_portrait(simulation: SimulationResult, x=0, y=1, filename=None)¶
Plot the phase portrait.
- Parameters:
simulation (SimulationResult) –
x (int) – Index of the component that is plotted on the x-axis.
y (int) – Index of the component that is plotted on the y-axis.
filename (str) – If a filename (path) is provided, the plot is saved.
Observables¶
- example_gni_project.plot_observable(simulation: SimulationResult, name: str, observable, filename=None)¶
Plot the evolution of an observable (scalar-valued function of the state).
- Parameters:
simulation (SimulationResult) –
name (str) – name / plot title
observable (function) – scalar-valued function of the state (e.g. energy)
filename (str) – If a filename (path) is provided, the plot is saved.
Example
Plot just the first component of the state:
>>> import autograd.numpy as np >>> from example_gni_project import * >>> def vector_field(x): ... q, p = x ... return np.array([p, -q]) >>> ivp = IVP(("q", "p"), vector_field, np.array([1., 0.])) >>> simulation = simulate(ivp, explicit_euler, 0.1, 0.5) >>> plot_observable(simulation, "q", lambda x: x[0])