pwassist.plotting.scan.ScanPlotter#

class pwassist.plotting.scan.ScanPlotter(results)[source]#

Bases: BasePWAPlotter

Plotter for all results that scan across a range of bins, e.g. mass, t, etc.

Most methods will have an optional ‘kin_variable’ that specifies with kinematic quantity (mass, t, energy, or some other ‘data’ dataframe column) they want to scan across. This is paired with a ‘stat’ argument determining the bin centroid and edges, and optional t/energy/mass bin selections in case the results bundle spans multiple bins for the non-plotted scan variable.

Parameters:

results (Results)

amplitudes(fractional=False, sharey=False, reflectivity='all', kin_variable='m', stat='edges', t_bin=None, energy_bin=None, mass_bin=None, indices=None, axs=None, kwargs=None)[source]#

Plot a grid of amplitudes, organized by spin (rows) and projection (columns)

This plot will create a grid of all amplitudes plotted as a function of the selected kinematic variable, with the rows corresponding to the spin+parity+angular momenta combo (J^P L) and the columns corresponding to the spin-projection m. Any quantum numbers unavailable due to the naming scheme are dropped. Reflectivities are plotted together in the same plot, with the option to select only positive or negative reflectivities.

Parameters:
  • fractional (bool) – Whether to plot the amplitudes as a fraction of the total intensity. Defaults to False.

  • sharey (bool) – Whether to share the y-axis across all amplitude plots. Defaults to False.

  • reflectivity (Literal['positive', 'negative', 'all']) – Which reflectivity amplitudes to plot. Defaults to “all”.

  • kin_variable (str) – Shorthand (“m”, “t”, “e”) or exact ‘data’ dataframe column name for the kinematic variable to plot against. Defaults to “m” (mass).

  • stat (Literal['edges', 'avg']) – Whether x-value/error is from the bin center and (high-low)/2 ‘edges’ (default) or from the actual bin average and rms of the underlying data.

  • t_bin (tuple[float, float] | TBin | None) – Fixes the t bin to plot from if the results span multiple t bins. If only 1 t bin is available, specification is unnecessary. Defaults to None.

  • energy_bin (tuple[float, float] | EnergyBin | None) – Fixes the beam energy bin to plot from if the results span multiple energy bins. If only 1 energy bin is available, specification is unnecessary. Defaults to None.

  • mass_bin (tuple[float, float] | MassBin | None) – Fixes the mass bin to plot from if the results span multiple mass bins. If only 1 mass bin is available, specification is unnecessary. Defaults to None.

  • indices (list[int] | None) – Optional list of positions within the resolved kinematic bin to select specific bins. Defaults to None.

  • axs (ndarray | None) – Optional array of axes to plot on. If None, a new figure and axes will be created. Note that one must be careful that the axes shape matches the expected shape.

  • kwargs (dict[str, dict[str, Any]] | None) – Optional dictionary of keyword arguments to customize the plot appearance. Recognized keys are “positive” and “negative” mapping to a dict of matplotlib ‘errorbar’ kwargs that override the defaults for the respective reflectivity amplitudes. e.g. {“positive”: {“color”: “red”}, “negative”: {“color”: “blue”}}. Defaults to None.

Returns:

The array of axes objects containing the amplitude plots.

Return type:

ndarray

Raises:
  • ValueError – If the reflectivity argument is not one of “positive”, “negative”, or “all”. If no naming scheme could be determined from the amplitudes, or if a bin is given for the dimension being scanned over, or if multiple bins are present along a non-scanned dimension, leaving an ambiguous plot range.

  • IndexError – If the provided axes shape does not match the expected shape based on the number of amplitudes.

classmethod available_styles()#

List names of built-in styles available for use with set_style().

Return type:

list[str]

property bootstrap: DataFrame | None#
coherent_sum(sum_label, data_legend='GlueX-I Data', fractional=False, kin_variable='m', stat='edges', t_bin=None, energy_bin=None, mass_bin=None, indices=None, ax=None, kwargs=None)[source]#

Plot coherent sum group across the bins.

A sum group is defined by the quantum numbers that the sum groups together and the amplitude naming scheme. For example, in the JLme scheme, one can plot all the available JLe coherent sums i.e. those that sum over the spin-projection m. If not plotting as fit fractions (fractional=’false’), then data points are also plotted.

Parameters:
  • sum_label (str) – The label of the coherent sum group to plot. See the coherent_sums member of the Results class for a list of available sum groups and the amplitudes that belong to each group.

  • data_legend (str) – The legend label for the data points. Defaults to “GlueX-I Data”.

  • fractional (bool) – Whether to plot the sums as a fraction of the total intensity. Defaults to False.

  • kin_variable (str) – Shorthand (“m”, “t”, “e”) or exact ‘data’ dataframe column name for the kinematic variable to plot against. Default to ‘m’ (mass).

  • stat (Literal['edges', 'avg']) – Whether x-value/error is from the bin center and (high-low)/2 ‘edges’ (default) or from the actual bin average and rms of the underlying data.

  • t_bin (tuple[float, float] | TBin | None) – Fixes the t bin to plot from if the results span multiple t bins. If only 1 t bin is available, specification is unnecessary. Defaults to None.

  • energy_bin (tuple[float, float] | EnergyBin | None) – Fixes the beam energy bin to plot from if the results span multiple energy bins. If only 1 energy bin is available, specification is unnecessary. Defaults to None.

  • mass_bin (tuple[float, float] | MassBin | None) – Fixes the mass bin to plot from if the results span multiple mass bins. If only 1 mass bin is available, specification is unnecessary. Defaults to None.

  • indices (list[int] | None) – Optional list of positions within the resolved kinematic bin to select specific bins. Defaults to None.

  • ax (Axes | None) – Optional axes to plot on. If None, a new figure and axes will be created.

  • kwargs (dict[str, dict[str, Any]] | None) – Optional dictionary of keyword arguments for each coherent sum, passed directly to ax.errorbar

Raises:
  • KeyError – If the specified sum_label is not found in the coherent sums, or or if stat=’avg’ but the requested corresponding columns are not present in the ‘data’ dataframe.

  • ValueError – If a bin is given for the dimension being scanned over, or if multiple bins are present on a non-scammed dimension, leaving an ambiguous plot range.

Return type:

Axes

convergence_rate(kin_variable='m', stat='edges', t_bin=None, energy_bin=None, mass_bin=None, indices=None, ax=None, kwargs=None)[source]#

Plot the convergence rate of the fit across bins.

Requires randomized fits to be in the results. Plots the percentage of successful, failed, and converged-with-bad-error-matrix fits across the selected kinematic bins. This can be useful for diagnosing issues with the fit and understanding the stability of the fit across the mass range.

Parameters:
  • kin_variable (str) – Shorthand (“m”, “t”, “e”) or exact ‘data’ dataframe column name for the kinematic variable to plot against. Default to ‘m’ (mass).

  • stat (Literal['edges', 'avg']) – Whether x-value/error is from the bin center and (high-low)/2 ‘edges’ (default) or from the actual bin average and rms of the underlying data.

  • t_bin (tuple[float, float] | TBin | None) – Fixes the t bin to plot from if the results span multiple t bins. If only 1 t bin is available, specification is unnecessary. Defaults to None.

  • energy_bin (tuple[float, float] | EnergyBin | None) – Fixes the beam energy bin to plot from if the results span multiple energy bins. If only 1 energy bin is available, specification is unnecessary. Defaults to None.

  • mass_bin (tuple[float, float] | MassBin | None) – Fixes the mass bin to plot from if the results span multiple mass bins. If only 1 mass bin is available, specification is unnecessary. Defaults to None.

  • indices (list[int] | None) – Optional list of positions within the resolved kinematic bin to select specific bins. Defaults to None.

  • ax (Axes | None) – Optional axes to plot on. If None, a new figure and axes will be created.

  • kwargs (dict[str, Any] | None) – Optional dictionary of keyword arguments to customize the plot appearance. Organized per fit status type as ‘successful’, ‘bad error matrix’, ‘failed’, so given value lists should be in the same ordering e.g. “labels” : [“Success”, “Bad Error”, “Failed”].

Returns:

The axes object containing the convergence rate plot.

Return type:

Axes

Raises:

KeyError – If randomized fits are not available in the results.

property correlation: DataFrame | None#
property covariance: DataFrame | None#
property data: DataFrame#
property fit: DataFrame#
classmethod get_style_name()#

Return name or path of the current style used by all plotters

Return type:

str

classmethod get_style_path()#

Return the path to the current style used by all plotters

Return type:

Path

interference(amp1, amp2, indices=None, amp1_kwargs=None, amp2_kwargs=None, amp_ax=None, phase_ax=None)[source]#

Plot two amplitudes and their interference phase as a function of mass.

Parameters:
  • amp1 (str) – The label of the first amplitude to plot.

  • amp2 (str) – The label of the second amplitude to plot.

  • indices (list[int] | None) – Optional list of indices to select specific mass bins. If None, all bins will be plotted.

  • amp1_kwargs (dict[str, Any] | None) – Optional dictionary of keyword arguments to customize the appearance of the first amplitude plot.

  • amp2_kwargs (dict[str, Any] | None) – Optional dictionary of keyword arguments to customize the appearance of the second amplitude plot.

  • amp_ax (Axes | None) – Optional axes to plot the amplitudes on. If None, a new figure and axes will be created.

  • phase_ax (Axes | None) – Optional axes to plot the phase difference on. If None, a new figure and axes will be created.

Returns:

The array of axes objects containing the amplitude and phase

difference plots.

Return type:

ndarray

Raises:
  • KeyError – If either phase is not in the fit results.

  • ValueError – If only one of amp_ax or phase_ax is provided, but not both

likelihood_distribution(delta_lnL_groups=None, kin_variable='m', stat='edges', t_bin=None, energy_bin=None, mass_bin=None, indices=None, ax=None, kwargs=None)[source]#

Plot the number of fits that fall within a group of delta lnL ranges.

Each kinematic bin will plot len(delta_lnLgroups)-1 bars, where each bar corresponds to the number of fits that fall within the delta lnL range defined by the delta_lnL_groups. For example, if delta_lnL_groups = (0, 1, 5, np.inf) ( the default setting), then the first bar will be the number of fits with delta lnL in (0, 1], and so on. The delta lnL is calculated as the difference between a randomized fit’s likelihood and the minimum likelihood in that bin.

Parameters:
  • delta_lnL_groups (tuple[float, ...] | None) – Groups of ranges to count delta lnL within. Defaults to None.

  • kin_variable (str) – Shorthand (“m”, “t”, “e”) or exact ‘data’ dataframe column name for the kinematic variable to plot against. Default to ‘m’ (mass).

  • stat (Literal['edges', 'avg']) – Whether x-value/error is from the bin center and (high-low)/2 ‘edges’ (default) or from the actual bin average and rms of the underlying data.

  • t_bin (tuple[float, float] | TBin | None) – Fixes the t bin to plot from if the results span multiple t bins. If only 1 t bin is available, specification is unnecessary. Defaults to None.

  • energy_bin (tuple[float, float] | EnergyBin | None) – Fixes the beam energy bin to plot from if the results span multiple energy bins. If only 1 energy bin is available, specification is unnecessary. Defaults to None.

  • mass_bin (tuple[float, float] | MassBin | None) – Fixes the mass bin to plot from if the results span multiple mass bins. If only 1 mass bin is available, specification is unnecessary. Defaults to None.

  • indices (list[int] | None) – Optional list of positions within the resolved kinematic bin to select specific bins. Defaults to None.

  • ax (Axes | None) – Optional axes to plot on. If None, a new figure and axes will be created.

  • kwargs (dict[str, Any] | None) – Optional dictionary of keyword arguments to customize the plot appearance. Passed directly to ax.grouped_bar() call, so see that method for details. Defaults to None.

Raises:

KeyError – if no randomized fit results are available.

Returns:

The axes object containing the likelihood distribution

plot.

Return type:

Axes

model_matrix(stat='edges', t_bin=None, energy_bin=None, indices=None, axs=None, kwargs=None)[source]#

Plot the entire model behavior as a function of mass in a matrix of plots

Each row/column is a “wave”: an amplitude with its reflectivity removed (e.g. J^P L_m). The diagonal shows the intensity of each wave, with both reflectivities overlaid. The off-diagonal plots show the phase difference between the row and column waves. The upper triangle is for the positive reflectivity amplitudes, and the lower triangle for the negative. Since the sign of a phase difference is ambiguous, both +|phase| and -|phase| are drawn. Uncertainties are drawn as filled bands, as the subplots are small.

Parameters:
  • stat (Literal['edges', 'avg']) – Whether x-value is from the bin center ‘edges’ (default) or from the actual bin average of the underlying data.

  • t_bin (tuple[float, float] | TBin | None) – Fixes the t bin to plot from if the results span multiple t bins. If only 1 t bin is available, specification is unnecessary. Defaults to None.

  • energy_bin (tuple[float, float] | EnergyBin | None) – Fixes the beam energy bin to plot from if the results span multiple energy bins. If only 1 energy bin is available, specification is unnecessary. Defaults to None.

  • indices (list[int] | None) – Optional list of positions within the resolved mass scan to select specific bins. If None, all bins will be plotted.

  • axs (ndarray | None) – Optional array of axes to plot on. If None, a new figure and axes will be created. Note that one must be careful that the axes shape matches the expected shape (n_waves, n_waves).

  • kwargs (dict[str, dict[str, Any]] | None) – Optional dictionary of matplotlib ‘plot’ kwargs overriding the defaults for each reflectivity, e.g. {“positive”: {“color”: “red”}, “negative”: {“linewidth”: 2}}. The uncertainty band takes its color from the “color” entry.

Returns:

The (n_waves, n_waves) array of axes objects containing the

intensity and phase difference plots.

Return type:

ndarray

Raises:
  • KeyError – If no amplitudes are found in the results.

  • IndexError – If the provided axes shape does not match the expected shape based on the number of waves.

  • ValueError – If multiple t or energy bins are present and not fixed, leaving an ambiguous plot range.

property norm_int: DataFrame | None#
property randomized: DataFrame | None#
ridgeline(columns, overlap=1.5, scale='global', equidistant=False, bw_method=None, n_points=256, cmap='Dark2', kin_variable='m', stat='edges', t_bin=None, energy_bin=None, mass_bin=None, indices=None, ax=None, kwargs=None)[source]#

Create a ridgeline (joyplot) of bootstrap distributions across a scan.

Each kinematic bin gets one “ridge” per column, a KDE of the bootstrap distribution for the column, drawn on a baseline located at the bin’s position along the scan variable (y-axis). The column values are on the x-axis. Ridges from lower values are drawn in front of those from higher values.

Parameters:
  • columns (list[str]) – Columns of the ‘bootstrap’ frame to plot. Each is given a different color, in the order given by cmap.

  • overlap (float) – Control how much neighboring ridges overlap, as the height of the teallest ridge in units of baseline spacing (median distance between adjacent bins). overlap=1.0: tallest ridge just touches the next baseline. overlap<1.0 leaves gaps. Defaults to 1.5.

  • scale (Literal['global', 'ridge']) – ‘global’ (default) scales all KDEs by a single common factor, so narrower distributions appear taller. ‘ridge’ scale each KDE to the same peak height, useful when widths vary largely between bins or columns.

  • equidistant (bool) – If True, the baselines are evenly spaced, one step per bin in scan order. y tick-labels still show each bin’s value as usual. If False (default), baselines sit at actual bin positions at scale.

  • bw_method (str | float | None) – KDE bandwidth, passed to scipy.stats.gaussian_kde. Can be ‘scott’ or ‘silverman’, or a scalar bandwidth factor. Defaults to None, or Scott’s rule.

  • n_points (int) – Number of x points each KDE is evaluated on. Defaults to 256.

  • cmap (str) – Name of qualitative matplotlib colormap used to color the columns. Cycles if there are more columns than colors. Defaults to “Dark2”.

  • kin_variable (str) – Shorthand (“m”, “t”, “e”) or exact ‘data’ dataframe column name for the kinematic variable to plot against. Default to ‘m’ (mass).

  • stat (Literal['edges', 'avg']) – Whether x-value/error is from the bin center and (high-low)/2 ‘edges’ (default) or from the actual bin average and rms of the underlying data.

  • t_bin (tuple[float, float] | TBin | None) – Fixes the t bin to plot from if the results span multiple t bins. If only 1 t bin is available, specification is unnecessary. Defaults to None.

  • energy_bin (tuple[float, float] | EnergyBin | None) – Fixes the beam energy bin to plot from if the results span multiple energy bins. If only 1 energy bin is available, specification is unnecessary. Defaults to None.

  • mass_bin (tuple[float, float] | MassBin | None) – Fixes the mass bin to plot from if the results span multiple mass bins. If only 1 mass bin is available, specification is unnecessary. Defaults to None.

  • indices (list[int] | None) – Optional list of positions within the resolved kinematic bin to select specific bins. Defaults to None.

  • ax (Axes | None) – Optional axes to plot on. If None, a new figure and axes will be created.

  • kwargs (dict[str, Any] | None) – Optional dictionary of keyword arguments to customize the plot appearance. Recognized keys are ‘colors’ (list of one color per column, overriding ‘cmap’), ‘alpha’ (fill transparency) and ‘linewidth’ (KDE outline width, default 1.0).

Returns:

The axes object containing the ridgeline plot

Return type:

Axes

Raises:
  • KeyError – If bootstrap dataframe is not in the results, or any requested columns are not found.

  • ValueError – If no columns are requested, ‘overlap’ < 0, ‘scale’ is not in list options, ‘n_points’ < 2, or no KDE can be computed.

classmethod set_style(style)#

Set global matplotlib style used by all plotters

Parameters:

style (str | Path) – Either a built-in style name (from available_styles()) or a path to a custom .mplstyle file.

Raises:

ValueError – If the style is not a valid built-in style or a valid file path.

Return type:

None