cminject.utils.visualization package

Code for visualization of virtual experiment results.

cminject.utils.visualization.plot_detector(detector: numpy.array, dimension_description: Union[str, Callable[[numpy.array], Any]], ax: matplotlib.axes._axes.Axes, **kwargs)

Plots 1D/2D histograms of one or a pair of measured quantities at a single detector.

Parameters
Returns

The result of the plt.hist/hist2d call made to plot the 1D/2D histogram.

cminject.utils.visualization.plot_detectors(detectors: Dict[str, numpy.array], dimension_description: str, axes: Union[None, matplotlib.axes._axes.Axes, List[matplotlib.axes._axes.Axes]] = None, **kwargs)

Plots 1D/2D histograms of one or a pair of measured quantities at multiple detectors.

Parameters
  • detectors – The list of detectors, i.e., a list of what plot_detector() accepts.

  • dimension_description – See docs for plot_detector().

  • axes – A list of axes or a single axis (plt.Axes instance). If one axis is passed, all plots will be made on that same axis; if a list of axes is passed, each detector will be plotted on the corresponding axis (by list position). This also means that if multiple axes are passed, len(axes) must be equal to len(detectors).

  • kwargs – Keyword args that will be passed directly to the plt.hist/hist2d calls.

Returns

A list of all return values of plot_detector().

cminject.utils.visualization.plot_trajectories(trajectories: Sequence[numpy.array], ax: Optional[matplotlib.axes._axes.Axes] = None, **plot_kwargs)

Plots multiple trajectories as simple line plots (plt.plot).

Parameters
  • trajectories – An iterable of trajectories.

  • ax – The axis to plot on; if None, a new figure and axis will be created.

  • plot_kwargs – Keyword arguments that will be passed directly to ax.plot.

Returns

A list of the values returned by each ax.plot call.

cminject.utils.visualization.plot_trajectories_colored(trajectories: Sequence[numpy.array], ax: Optional[matplotlib.axes._axes.Axes] = None, autoscale: bool = True, **line_collection_kwargs)

Plots multiple trajectories, segments colored by the magnitude of the (approximate) velocities.

Parameters
  • trajectories – A sequence of trajectories.

  • ax – The axis to plot on; if None, a new figure and axis will be created.

  • autoscale – If True, the axes will be scaled to fit the created LineCollection/Line3DCollection.

  • line_collection_kwargs – Keyword arguments that will be passed directly to the Line[3D]Collection constructor.

Returns

The Line[3D]Collection object representing all plotted lines.

cminject.utils.visualization.plot_trajectories_movie(trajectories: Sequence[numpy.array], dimension_description: Union[str, Callable[[numpy.array], Any]] = 'x,z', delay: int = 100, n_previous: int = 10, ax: Optional[matplotlib.axes._axes.Axes] = None, animation_kwargs: Optional[Dict] = None, plot_kwargs: Optional[Dict] = None, update_fn: Optional[Callable[[int, List[matplotlib.artist.Artist]], List[matplotlib.artist.Artist]]] = None) -> (<class 'matplotlib.animation.Animation'>, <class 'matplotlib.figure.Figure'>, <class 'int'>)

Creates a trajectory movie via a matplotlib.animation.Animation. Plots each trajectory as a curve of the last n_previous positions.

Parameters
  • trajectories – A sequence of trajectories.

  • dimension_description – A dimension descriptionf of a pair or triple of dimensions.

  • delay – The delay between each animation frame.

  • n_previous – The number of previous positions to include in each curve. When equal to one, each curve

  • ax – (optional) a specific Axes instance to plot on. If not passed, a new Figure and Axes are created.

  • animation_kwargs – (optional) arguments to pass to matplotlib.animation.FuncAnimation

  • plot_kwargs – (optional) arguments to pass to the initial plt.plot() calls that draw each line

  • update_fn – (optional) An update function to be called as the last step in each animation iteration. Receives the current iteration number and the list of artists that the default update function returns. Must return a list of artists, just like animation update functions.

Returns

A 3-tuple of (created Animation instance, created Figure instance, number of animation frames).