Show1D#

class quantem.widget.Show1D(**kwargs: Any)[source]#

Bases: AnyWidget

Interactive 1D data viewer for spectra, profiles, and time series.

Display one or more 1D traces with interactive zoom, pan, cursor readout, and calibrated axes. Supports log scale, grid lines, legend, and publication-quality export.

Parameters:
  • data (array_like) – 1D array for a single trace, 2D array (n_traces, n_points) for multiple traces, or a list of 1D arrays.

  • x (array_like, optional) – Shared X-axis values. Must have the same length as data points. If not provided, uses integer indices [0, 1, 2, …].

  • labels (list of str, optional) – Labels for each trace. Used in legend and stats bar.

  • colors (list of str, optional) – Hex color strings for each trace. If not provided, uses a default 8-color palette.

  • title (str, optional) – Title displayed above the plot.

  • x_label (str, optional) – Label for the X axis (e.g. “Energy”, “Distance”, “Epoch”).

  • y_label (str, optional) – Label for the Y axis (e.g. “Counts”, “Intensity”, “Loss”).

  • x_unit (str, optional) – Unit for the X axis (e.g. “eV”, “nm”, “”).

  • y_unit (str, optional) – Unit for the Y axis.

  • log_scale (bool, default False) – Use logarithmic Y axis.

  • auto_contrast (bool, default False) – Clip Y-axis range to [percentile_low, percentile_high] of the data, revealing weak features hidden by outliers (e.g. core-loss edges behind a zero-loss peak in EELS).

  • percentile_low (float, default 2.0) – Lower percentile for auto-contrast clipping (0–100).

  • percentile_high (float, default 98.0) – Upper percentile for auto-contrast clipping (0–100).

  • show_stats (bool, default True) – Show statistics bar (mean, min, max, std per trace).

  • show_legend (bool, default True) – Show legend when multiple traces are displayed.

  • show_grid (bool, default True) – Show grid lines on the plot.

  • show_controls (bool, default True) – Show control row below the plot.

  • line_width (float, default 1.5) – Line width for traces.

  • grid_density (int, default 10) – Number of grid divisions per axis (5–50).

  • peak_active (bool, default False) – Whether peak placement mode is on.

  • disabled_tools (list of str, optional) – Tool groups to lock (visible but non-interactive): "display", "peaks", "stats", "export", "all".

  • disable_* (bool, optional) – Convenience flags (disable_display, disable_peaks, disable_stats, disable_export, disable_all) equivalent to adding those keys to disabled_tools.

  • hidden_tools (list of str, optional) – Tool groups to hide (not rendered). Same values as disabled_tools.

  • hide_* (bool, optional) – Convenience flags mirroring disable_* for hidden_tools.

  • state (dict or str or Path, optional) – Restore display settings from a dict or a JSON file path.

Examples

>>> import numpy as np
>>> from quantem.widget import Show1D
>>>
>>> # Single trace
>>> Show1D(np.sin(np.linspace(0, 10, 200)))
>>>
>>> # Multiple traces with labels
>>> x = np.linspace(0, 10, 200)
>>> Show1D([np.sin(x), np.cos(x)], x=x, labels=["sin", "cos"])
>>>
>>> # Optimization loss curve
>>> Show1D(losses, x_label="Epoch", y_label="Loss", log_scale=True)

Key Methods

Show1D.set_data(data, x=None, labels=None) Self[source]#

Replace displayed data. Preserves display settings.

Parameters:
  • data (array_like) – 1D, 2D (n_traces, n_points), or list of 1D arrays.

  • x (array_like, optional) – New X-axis values.

  • labels (list of str, optional) – New trace labels. If not provided, generates defaults.

Show1D.add_trace(y, label=None, color=None) Self[source]#

Append a trace.

Parameters:
  • y (array_like) – 1D array with the same number of points as existing traces.

  • label (str, optional) – Trace label.

  • color (str, optional) – Hex color string.

Show1D.remove_trace(index: int) Self[source]#

Remove a trace by index.

Parameters:

index (int) – Zero-based trace index.

Show1D.clear() Self[source]#

Remove all traces.

Show1D.find_peaks(trace_idx: int = 0, *, height=None, prominence: float = 0.01, distance: int = 1, width=None) Self[source]#

Auto-detect peaks using scipy.signal.find_peaks.

Parameters:
  • trace_idx (int) – Trace index to search.

  • height (float, optional) – Minimum peak height.

  • prominence (float) – Minimum peak prominence (default 0.01).

  • distance (int) – Minimum horizontal distance between peaks in samples.

  • width (float, optional) – Minimum peak width in samples.

Show1D.add_peak(x: float, trace_idx: int = 0, label: str = '') Self[source]#

Add a peak marker at the given X position.

Finds the nearest data point and searches ±5 points for a local maximum.

Parameters:
  • x (float) – X-axis value near the desired peak.

  • trace_idx (int) – Trace index to search for the peak.

  • label (str) – Optional label for the peak marker.

Show1D.remove_peak(index: int = -1) Self[source]#

Remove a peak marker by index (default: last).

Show1D.clear_peaks() Self[source]#

Remove all peak markers.

Show1D.measure_fwhm(peak_idx: int | None = None) Self[source]#

Compute FWHM for selected peaks (or a specific peak).

Parameters:

peak_idx (int, optional) – If given, adds this peak to the selection before computing.

Show1D.export_peaks(path: str) Path[source]#

Export peak markers to CSV or JSON.

Format is inferred from the file extension (.csv or .json).

Parameters:

path (str) – Output file path.

Show1D.save_image(path: str | Path, *, format: str | None = None, dpi: int = 150, include_peaks: bool = True) Path[source]#

Save publication-quality figure as PNG or PDF.

Renders traces, grid, axes, labels, and peak markers using matplotlib.

Parameters:
  • path (str or pathlib.Path) – Output file path.

  • format (str, optional) – "png" or "pdf". Inferred from extension if omitted.

  • dpi (int) – Output resolution (default 150).

  • include_peaks (bool) – Render peak markers on the figure (default True).

Returns:

The written file path.

Return type:

pathlib.Path

Show1D.state_dict()[source]#
Show1D.save(path: str)[source]#
Show1D.load_state_dict(state)[source]#
Show1D.summary()[source]#