anyplotlib.RangeWidget#

class anyplotlib.RangeWidget(push_fn, *, x0, x1, color='#00e5ff', style='band', y=0.0, linewidth=2, max_extent=None, orientation='horizontal', snap_values=None)[source]#

Bases: Widget

Draggable range selection widget.

Two display styles are available:

style='band' (default)

Two connected vertical lines with a translucent fill band. Either line can be dragged independently; the whole band can be dragged by clicking inside it.

style='fwhm'

Two circular handles joined by a dashed horizontal line drawn at height y (the half-maximum level). Only the x-positions of the handles are draggable. Use this to show/edit a FWHM interval on a peak.

With orientation='vertical' the band spans the plot width and selects a range on the value axis instead — for picking an intensity window rather than a spectral one.

Parameters:
  • push_fn (Callable) – Update callback.

  • x0 (float) – The two edges of the range, in data coordinates along the selection axis: x positions when horizontal, y values when vertical. The names do not change with orientation, mirroring how matplotlib’s SpanSelector.extents is read the same way for either direction.

  • x1 (float) – The two edges of the range, in data coordinates along the selection axis: x positions when horizontal, y values when vertical. The names do not change with orientation, mirroring how matplotlib’s SpanSelector.extents is read the same way for either direction.

  • color (str, optional) – CSS colour. Default "#00e5ff".

  • style ({'band', 'fwhm'}, optional) – Visual style. Default "band". 'fwhm' is horizontal-only.

  • y (float, optional) – Y-position (data coordinates) for the connecting line when style='fwhm'. Ignored for style='band'. Default 0.0.

  • orientation ({'horizontal', 'vertical'}, optional) – Which axis the range selects along. Default "horizontal".

  • linewidth (float, optional) – Line stroke width in px. Default 2.

  • max_extent (float, optional) –

    Maximum span width in DATA units. When set, the span physically stops growing at this width while dragging: the edge under the cursor is pinned and the opposite edge stays put, so the range never exceeds the cap and never jumps. None (default) leaves it unbounded.

    Use this when span width costs real work downstream — e.g. an integrating selector where the width is a number of frames to read. Enforcing it in the widget makes the limit visible (the edge simply stops) instead of applying a silent clamp after the fact.

  • snap_values (sequence of float, optional) – Allowed edge positions. While dragging, each edge follows the cursor but lands only on the nearest of these values — matplotlib’s SpanSelector.snap_values. None (default) drags continuously. Set it later with widget.snap_values = [...].

Raises:

ValueError – If orientation is not 'horizontal' or 'vertical', or if style='fwhm' is combined with a vertical orientation.