Skip to content

clamp-max

Input Stack:
maxValue: Double
expr: TimeSeriesExpr
Output Stack:
TimeSeriesExpr
 

Limit the maximum value of a time series by clamping values above a specified threshold. Any values greater than the maximum will be set to the maximum value, while values at or below the maximum remain unchanged. This is useful for controlling visualization scaling and handling occasional data spikes.

Parameters

  • expr: The time series expression to apply the maximum limit to
  • maxValue: The maximum allowed value (values above this will be clamped)

Behavior

  • Values ≤ maxValue: Remain unchanged
  • Values > maxValue: Are set to exactly maxValue
  • Missing data: NaN values are preserved as NaN

Problem and Solution

The axis parameters for controlling axis bounds have limitations:

  • They apply to everything on the axis and cannot target specific lines
  • For data with occasional spikes, they can hide important details in the rest of the data

Consider this graph with a data spike:

Original Data

The spike makes it difficult to see details at other times. While alternate axis scales like logarithmic can help, linear scales are often easier to reason about.

Using :clamp-max to limit to a known reasonable maximum (e.g., 25) improves readability:

Clamped Data

Examples

Clamping to prevent spikes from dominating the scale:

BeforeAfter
name,sps,:eq,
:sum
name,sps,:eq,
:sum,
60e3,:clamp-max
  • :clamp-min - Limit minimum values (floor operation)

See Also

  • Axis Bounds - Global axis scaling options
  • Axis Scale - Alternative approaches for handling extreme values