at.plot.observables#

Functions

plot_observables(ring, obsleft, *obsright[, ...])

Plot element observables along a lattice.

plot_observables(ring, obsleft, *obsright, s_range=None, axes=None, xlabel='', ylabel='', slices=400, **kwargs)[source]#

Plot element observables along a lattice.

Parameters:
  • ring (Lattice) – Lattice description

  • obsleft (ObservableList) – List of ElementObservable plotted against the left axis. if refpts is All, a line is drawn. Otherwise, markers are drawn. It is recommended to use Observables with scalar values. Otherwise, all the values are plotted but share the same line properties and legend,

  • obsright (ObservableList) – Optional list of ElementObservable plotted against the right axis,

  • axes (Axes | None) – Axes in which the observables are plotted. if None, a new figure is created,

  • s_range (tuple[float, float] | None) – Lattice range of interest, default: whole lattice,

  • slices (int) – Number of lattice slices for getting smooth curves. Default: 400.

  • xlabel (str) – x-axis label. Default: s [m].

  • ylabel (str) – y-axis label. Default: ObservableList.axis_label.

The following keywords are transmitted to the plot_synopt() function.They apply to the main (left) axis and are ignored when plotting in exising axes:

Keyword Arguments:
  • labels (Refpts) – Select elements for which the name is displayed. Default: None,

  • dipole (dict) – Dictionary of properties overloading the default properties of the dipole representation. Example: {"facecolor": "xkcd:electric blue"}. If None, dipoles are not shown.

  • quadrupole (dict) – Same definition as for dipole,

  • sextupole (dict) – Same definition as for dipole,

  • multipole (dict) – Same definition as for dipole,

  • monitor (dict) – Same definition as for dipole.

The following keyword arguments are transmitted to the Axes creation function.They apply to the main (left) axis and are ignored when plotting in exising axes:

Keyword Arguments:
  • title (str) – Plot title,

  • ylim (tuple) – Y-axis limits,

  • * – for other keywords see add_subplot

Returns:

axes – tuple of Axes. Contains 2 elements if there is a plot on the right y-axis, 1 element otherwise.

Note

The legend of the plot is controlled by the Observable.label attributes. Default values are provided, but labels may explicitly set.

Labels may contain LaTeX math code. Example: "$\beta_x$" will appear as “\(\beta_x\)”.

Labels starting with an underscore do not appear in the legend.

Examples

Minimal example using default values:

>>> obsmu = at.ObservableList(
...     [
...         at.LocalOpticsObservable(at.All, "mu", plane=0),
...         at.LocalOpticsObservable(at.All, "mu", plane=1),
...     ]
... )
>>>
>>> (ax1,) = at.plot_observables(ring, obsmu)
phase advance plot

This example demonstrates the use of the postfun post-processing attribute of observables to plot the beam envelopes for arbitrary emitttance values:

>>> # Define the emittances
>>> emit_x = 130.0e-12
>>> emit_y = 10.0e-12
>>>
>>> # beam size computation
>>> sigma_x = lambda x: 1.0e6 * np.sqrt(x * emit_x)  # result in um
>>> sigma_y = lambda y: 1.0e6 * np.sqrt(y * emit_y)  # result in um
>>>
>>> # Observables
>>> obsenv = at.ObservableList(
...     [
...         at.LocalOpticsObservable(
...             at.All, "beta", plane="x", postfun=sigma_x, label=r"$\sigma_x$"
...         ),
...         at.LocalOpticsObservable(
...             at.All, "beta", plane="y", postfun=sigma_y, label=r"$\sigma_y$"
...         ),
...     ]
... )
>>> (ax2,) = at.plot_observables(
...     ring, obsenv, ylabel=r"Beam size [${\mu}m$]", title="Beam envelopes"
... )
>>> )
envelope plot