Plotting with the Step class

Several diagnostics are available with the Step class.

hist1D and hist2D functions

twissed.Step.hist1D(self, xname: str, xconv: str | None = None, xrange: List[float | None] | None = [None, None], yname: str | None = 'charge', yconv: str | None = None, yrange: List[float | None] | None = [None, None], bins: int | None = 100, dx: int | None = None, plot: str | None = 'plot', ax: Axes | None = None, **kwargs: Any) Tuple[ndarray, ndarray]

Plot/get 1D histogram data from the weighted beam.

Example

Simple plot of the x distribution (dQ/dx).
# Note that x axis is convert in um with xconv. step.sigma_x is the standard deviation (bunch length) in x.
H, xpos = step.hist1D('x',
                    xconv='um',
                    xrange=[-3*step.sigma_x*1e6,3*step.sigma_x*1e6],
                    bins=150,
                    # dx = 1, # Instead of bins
                    plot='plot',
                    linestyle='--',
                    fwhm=True,
                    )
Multiple plots.
fig, axs = plt.subplots(2,3, figsize=(4*3,4*2), dpi=100, tight_layout=True)
fig.suptitle(f"dQ/dE with various options")

H, xpos = step.hist1D('Ek',dx=1,plot='plot',ax=axs[0,0])
_ = axs[0,0].set_title(f"plot: dx = 1 ($\Delta$E = { xpos[1]-xpos[0] :.2f})")

H, xpos = step.hist1D('Ek',bins=50,plot='plot',ax=axs[0,1])
_ = axs[0,1].set_title(f"plot: bins=50 ($\Delta$E = { xpos[1]-xpos[0] :.2f})")

H, xpos = step.hist1D('Ek',bins=20,plot='hist',ax=axs[0,2])
_ = axs[0,2].set_title(f"hist: bins=20 ($\Delta$E = { xpos[1]-xpos[0] :.2f})")

H, xpos = step.hist1D('Ek',bins=50,plot='lineplot',ax=axs[1,0])
_ = axs[1,0].set_title(f"lineplot: bins=50")

H, xpos = step.hist1D('Ek',bins=40,plot='histplot',ax=axs[1,1])
_ = axs[1,1].set_title(f"histplot: bins=50")

H, xpos = step.hist1D('Ek',dx=1,plot='histplot',ax=axs[1,2])
_ = axs[1,2].set_title(f"histplot: dx=1")
Parameters:
  • xname (str) – Name of the beam value for the x axis (e.g. “x”,”uy”,”Ek”,…)

  • xconv (str, optional) – Unit wanted for the x axis. Defaults to None.

  • xrange (list, optional) – Range [min, max] of the data. Defaults to [None,None].

  • yname (str, optional) – Set the y axis. Defaults to ‘charge’.

  • yconv (str, optional) – Unit wanted for the y axis. Defaults to None.

  • yrange (list, optional) – Range [min, max] of the data. Defaults to [None,None].

  • bins (int, optional) – Number of bins used. Defaults to 100.

  • dx (float, optional) – Step in x wanted. Modify bins. Defaults to None.

  • plot (str, optional) – Type of plot wanted. Defaults to step.

  • ax (matplotlib.pyplot.axes, optional) – matplotlib.pyplot.axes object for plots. Defaults to None. If None, but plot != None, will create a new figure with its own ax.

  • **kwargs (List of properties) –

    • xlabel (bool): Plot xlabel. Defaults to True.

    • ylabel (bool): Plot xlabel. Defaults to True.

    • short (bool): Use short unit label. Defaults to False.

    • linestyle (str): Defaults to “-“.

    • fwhm (bool): Plot the FWHM limits. Defaults to False.

Returns:

  • hist (float) (array) – The values of the histogram. See density and weights for a description of the possible semantics.

  • xpos (float) (array of dtype float) – Return the bin positions (len(hist)) at the center of bins.

twissed.Step.hist2D(self, xname: str, yname: str, xconv: str | None = None, yconv: str | None = None, xrange: List[float | None] | None = [None, None], yrange: List[float | None] | None = [None, None], bins: List[int] | None = [100, 100], plot: str | None = 'pcolormesh', ax: Axes | None = None, iscbar: bool | None = True, emit: bool | None = True, vrange: List[float | None] | None = [None, None], **kwargs) Tuple[ndarray, ndarray, ndarray]

Plot/get 2D histogram data from the weighted beam.

Example

Simple plot of the x distribution (dQ/dx).
twissed_cmap = twissed.Cmap()

H, xpos, ypos = step.hist2D(
    'x',
    'xp',
    xconv='m',
    yconv='mrad',
    xrange=[- 3*step.sigma_x*1e0, 3*step.sigma_x*1e0],
    yrange=[- 3*step.sigma_xp*1e3, 3*step.sigma_xp*1e3],
    plot='pcolormesh_improved',
    cmap=twissed_cmap.cubehelix_r,
    emit=True,
)

Todo

Remove pcolormesh_improved. Add option for 1D histogram. Add more kwargs.

Parameters:
  • xname (str) – Name of the beam value for the x axis (e.g. “x”,”uy”,”Ek”,…)

  • yname (str) – Name of the beam value for the y axis (e.g. “x”,”uy”,”Ek”,…)

  • xconv (str, optional) – Unit wanted for the x axis. Defaults to None.

  • yconv (str, optional) – Unit wanted for the y axis. Defaults to None.

  • xrange (list, optional) – Range [min, max] of the x data.. Defaults to [np.nan,np.nan].

  • yrange (list, optional) – Range [min, max] of the y data.. Defaults to [np.nan,np.nan].

  • bins (list, optional) – Number of bins used. Defaults to [100,100].

  • plot (str, optional) – Type of plot wanted. Available: “pcolormesh”, “scatter”, “hist2D, “hexbin”, “bivariate”. Defaults to “pcolormesh”.

  • ax (matplotlib.pyplot.axes, optional) – matplotlib.pyplot.axes object for plots. Defaults to None. If None, but plot != None, will create a new figure with its own ax.

  • iscbar (bool, optional) – Plot colorbar. Defaults to True.

  • emit (bool, optional) – Plot emittance. Defaults to True.

  • **kwargs (List of properties) –

    • cmap (str): colormap of . Defaults to ‘tracewin’.

    • grid (str): Defaults to True.

    • shading (str): Pcolormesh shading. Defaults to “auto”. “gouraud” available.

    • vmin (float): Pcolormesh vmin. Defaults to None.

    • vmax (float): Pcolormesh vmax. Defaults to None.

    • xlabel (bool): Plot xlabel. Defaults to True.

    • ylabel (bool): Plot xlabel. Defaults to True.

    • short (bool): Use short unit label. Defaults to False.

    • set_xticks (list): Defaults to False.

    • set_yticks (list): Defaults to False.

    • marginals_bar (bool): Plot small 1d histogram (bar format). Defaults to False.

    • marginals_plot (bool): Plot small 1d histogram (plotline format). Defaults to False.

    • marginals_step (bool): Plot small 1d histogram (step format). Defaults to True.

    • marginals_color (str): Color of the small 1d histogram. Defaults to “firebrick”.

    • emit_color (str): Color of the emittance. Default to “firebrick”.

    • panel_text (str): Name of the panel. For instance: “(a)”, “(b)”, or “i)”.

Returns:

  • hist (float) (2D array) – The bi-dimensional histogram of samples x and y. Values in x are histogrammed along the first dimension and values in y are histogrammed along the second dimension.

  • xpos (float) (1D array) – The bin positions (middle) along the x-axis.

  • ypos (float) (1D array) – The bin positions (middle) along the y-axis.