yupi.graphics

This module constains a set of functions dadicated to plot trajectories and extracted statistical data from yupi.stats.

All the resources of this module should be imported directly from yupi.graphics.

plot_2d(trajs, line_style='-', title=None, legend=True, show=True, connected=False, color=None, ax=None, **kwargs)

Plot all the points of trajectories from trajs in a 2D plane.

Parameters:
  • trajs (list[Trajectory] | Trajectory) – Input trajectories.

  • line_style (str) – Type of the trajectory line to plot. It uses the matplotlib, notation, by default ‘-‘.

  • title (str, optional) – Title of the plot, by default None.

  • legend (bool, optional) – If True, legend is shown. By default True.

  • show (bool, optional) – If True, the plot is shown. By default True.

  • connected (bool) –

    If True, all the trajectory points of same index will be, connected.

    If the trajectories do not have same length then the points will be connected until the shortest trajectory last index.

  • color (str or tuple or list) –

    Defines the color of the trajectories, by default None.

    If color is of type str or tuple (rgb) then the color is applied to all trajectories. If color is of type list then the trajectories take the color according to the index.

    If there are less colors than trajectories then the remaining trajectories are colored automatically (not with the same color).

  • ax (matplotlib.axes.Axes, optional) –

    Axes where the plot is drawn, by default None.

    If None, then the current axes is used.

  • kwargs (Any)

Return type:

Axes

plot_3d(trajs, line_style='-', title=None, legend=True, show=True, connected=False, color=None, ax=None, **kwargs)

Plot all the points of trajectories from trajs in a 3D space.

Parameters:
  • trajs (list[Trajectory] | Trajectory) – Input trajectories.

  • line_style (str) – Type of the trajectory line to plot. It uses the matplotlib, notation, by default ‘-‘.

  • title (str, optional) – Title of the plot, by default None.

  • legend (bool, optional) – If True, legend is shown. By default True.

  • show (bool, optional) – If True, the plot is shown. By default True.

  • connected (bool) –

    If True, all the trajectory points of same index will be, connected.

    If the trajectories do not have same length then the points will be connected until the shortest trajectory last index.

  • color (str or tuple or list) –

    Defines the color of the trajectories, by default None.

    If color is of type str or tuple (rgb) then the color is applied to all trajectories. If color is of type list then the trajectories take the color according to the index.

    If there are less colors than trajectories then the remaining trajectories are colored automatically (not with the same color).

  • ax (matplotlib.axes.Axes, optional) –

    Axes where the plot is drawn, by default None.

    If None, then a new axes is created with projection=’3d’.

  • kwargs (Any)

Return type:

Axes3D

plot_angles_hist(ang, bins, show=True, ax=None, **kwargs)

Plot a histogram of the array of angles ang.

Parameters:
  • ang (np.ndarray) – Array of angles.

  • bins (int) – Number of histogram bins.

  • show (bool, optional) – If True, the plot is shown. By default True.

  • ax (Axes, optional) – Axes to plot. By default None.

  • kwargs (Any)

Returns:

Axes of the plot.

Return type:

PolarAxes

Raises:

ValueError – If the axes is not polar.

plot_hist(values, **kwargs)

Plot a histogram of the given

Parameters:
  • values (np.ndarray) – Input values

  • kwargs (Any)

Returns:

Axes of the plot.

Return type:

Axes

plot_hists(values_list, kwargs_list=None, labels=None, filled=False, **general_kwargs)

Plot several histograms given a collection of values.

Parameters:
  • values_list (list[np.ndarray]) – Collection of values.

  • kwargs_list (list[dict] | None) –

    kwargs of each plot, by default []

    If given, the length must be the same as the length of values.

  • labels (list[str] | None) – Labels of each plot, by default None

  • filled (bool) – If True, the histogram is filled. By default False.

  • general_kwargs (Any) – General kwargs for all plots. By default {}

Returns:

Axes of the plot.

Return type:

Axes

plot_kurtosis(kurtosis, dt=None, t_array=None, kurtosis_ref=None, units='s', show=True, ref_color='#a6ec98', **kwargs)

Plot kurtosis.

Parameters:
  • kurtosis (np.adarray) – Kurtosis array.

  • dt (float) – Trajectories time step.

  • t_array (np.ndarray, optional) – Array of time instants that match with every value in kurtosis. By default None.

  • kurtosis_ref (float, optional) – The value of kurtosis for a gaussian.

  • units (str, optional) – Units of the time axes.

  • show (bool, optional) – If True, the plot is shown. By default True.

  • ref_color (Any, optional) – Color of the fill between the upper and lower bound. By default LIGHT_GREEN.

  • kwargs (Any)

Returns:

Axes of the plot.

Return type:

Axes

plot_msd(msd, msd_std, dt, lag, x_units='s', y_units='m^2', show=True, fill_color='#f7c790', **kwargs)

Plot Mean Square Displacement.

Parameters:
  • msd (np.ndarray) – Mean square displacement array.

  • msd_std (np.ndarray) – Standard deviation.

  • dt (float) – Trajectories time step.

  • lag (int) – Lag time.

  • x_units (str, optional) – Units of the time axes.

  • y_units (str, optional) – Units of the MSD axes.

  • show (bool, optional) – If True, the plot is shown. By default True.

  • fill_color (Any, optional) – Color of the fill between the upper and lower bound. By default LIGHT_ORANGE.

  • kwargs (Any)

Returns:

Axes of the plot.

Return type:

Axes

plot_psd(psd_mean, frec, psd_std=None, omega=True, show=True, **kwargs)

Plot the Power Spectral Density.

Parameters:
  • psd_mean (np.ndarray) – Power spectral density array.

  • frec (np.ndarray) – Array of frequencies.

  • psd_std (np.ndarray, optional) – Standard deviation of the power spectrum. By default None.

  • omega (bool, optional) – If True, the freq is instended to be in rad/s, otherwise in Hz. By default True.

  • show (bool, optional) – If True, the plot is shown. By default True.

  • kwargs (Any)

Returns:

Axes of the plot.

Return type:

Axes

plot_speed_hist(v, show=True, units='m/s', **kwargs)

Plot a histogram of the array of velocities v.

Parameters:
  • v (np.ndarray) – Velocity array.

  • show (bool, optional) – If True, the plot is shown. By default True.

  • units (string, optional) – Velocity units. By default ‘m/s’.

  • kwargs (Any)

Returns:

Axes of the plot.

Return type:

Axes

plot_vacf(vacf, dt, lag, x_units='s', y_units='(m/s)^2', log_inset=True, show=True, **kwargs)

Plot Velocity Autocorrelation Function.

Parameters:
  • vacf (np.ndarray) – Velocity autocorrelation function array.

  • dt (float) – Trajectories time step.

  • lag (int) – Number of steps that multiplied by dt defines the lag time.

  • x_units (str, optional) – Units of the time axes.

  • y_units (str, optional) – Units of the VACF axes.

  • log_inset (bool, optional) – If True, a log-log inset is shown. By default True.

  • show (bool, optional) – If True, the plot is shown. By default True.

  • kwargs (Any)

Returns:

Axes of the plot.

Return type:

Axes