dynamo.pl.plot_traj

dynamo.pl.plot_traj(f, y0, t, args=(), lw=2, background=None, integration_direction='both', save_show_or_return='return', save_kwargs={}, ax=None)[source]

Plots a trajectory on a phase portrait.

Code adapted from: http://be150.caltech.edu/2017/handouts/dynamical_systems_approaches.html

Parameters:
  • f (Callable) – the function for form f(y, t, *args). It would work as the right-hand-side of the dynamical system. Must return a 2-array.

  • y0 (Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]) – the initial condition.

  • t (Union[_SupportsArray[dtype], _NestedSequence[_SupportsArray[dtype]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]) – the time points for trajectory.

  • args (Sequence[Any]) – additional arguments to be passed to f. Defaults to ().

  • lw (float) – the line width of the trajectory. Defaults to 2.

  • background (Optional[str]) – the background color of the plot. Defaults to None.

  • integration_direction (Literal['forward', 'backward', 'both']) – Determines whether to integrate the trajectory in the forward, backward, or both direction. Default to “both”.

  • save_show_or_return (Literal['save', 'show', 'return']) – whether to save, show or return the figure. Defaults to “return”.

  • save_kwargs (Dict[str, Any]) – a dictionary that will be passed to the save_show_ret function. By default, it is an empty dictionary and the save_show_ret function will use the {“path”: None, “prefix”: ‘plot_traj’, “dpi”: None, “ext”: ‘pdf’, “transparent”: True, “close”: True, “verbose”: True} as its parameters. Otherwise, you can provide a dictionary that properly modify those keys according to your needs. Defaults to {}.

  • ax (Optional[Axes]) – the axis on which to make the plot. If None, new axis would be created. Defaults to None.

Return type:

Optional[Axes]

Returns:

None would be returned by default. If save_show_or_return is set to be ‘return’, the Axes of the generated figure would be returned.