Plot any scalar
Rerun can plot numerical data as a time series, even data that wasn't logged with Rerun semantics.
By remapping where a visualizer reads its inputs from, you can separate how you model your data from how you visualize it.
This is useful for plotting custom messages from MCAPs, or data logged via AnyValues and DynamicArchetype.
As a bonus, logging multiple scalars to the same entity can drastically reduce .rrd file sizes.
Each visualizer takes components as input and determines their values from various sources. By configuring component mappings, you can control exactly where each input comes from.
The supported data types are:
Float32andFloat64Int8,Int16,Int32, andInt64UInt8,UInt16,UInt32, andUInt64Boolean- Any of the above nested inside of Arrow structs.
For background on how visualizers resolve component values, see Customize views.
Logging custom data logging-custom-data
Use DynamicArchetype to send data with custom component names alongside regular Rerun data.
Flat arrays and Arrow StructArrays are both supported.
This is what the data looks like for the /plot entity:
# Custom scalar batch with a cos using a custom component name.
*rr.DynamicArchetype.columns(archetype="custom", components={"my_custom_scalar": np.cos(times / 10.0)}),
# Nested custom scalar batch with a sigmoid inside a struct.
*rr.DynamicArchetype.columns(
archetype="custom", components={"my_nested_scalar": make_sigmoid_struct_array(64)}
),Remapping components remapping-components
A visualizer can source its inputs from any component with a compatible datatype.
For example, the SeriesLines visualizer accepts any numerical data for its Scalar input.
This works with data from MCAP files, AnyValues, or DynamicArchetype.
Optional components like Names and Colors can be sourced similarly from arbitrary data.
The following remaps the Scalars:scalars input to read from custom:my_custom_scalar instead:
rr.SeriesLines(names="cosine (custom)").visualizer(
mappings=[
# Map scalars to the custom component.
VisualizerComponentMapping(
target="Scalars:scalars",
source_kind=ComponentSourceKind.SourceComponent,
source_component="custom:my_custom_scalar", # Map from custom component
),
]
),Selectors for nested data selectors-for-nested-data
When your data lives inside an Arrow StructArray, use a selector to extract a specific field.
Selectors use a jq-inspired syntax (e.g. .values to select the values field).
Data types are automatically cast when compatible. For example, Float32 data will be cast to Float64 as needed by the visualizer.
Here is how to create a nested StructArray:
def make_sigmoid_struct_array(steps: int) -> pa.StructArray:
"""Creates a StructArray with a `values` field containing sigmoid data.
Note: We intentionally use float32 here to demonstrate that the data will be
automatically cast to the correct type (float64) when resolved by the visualizer.
"""
x = np.arange(steps, dtype=np.float32) / 10.0
sigmoid_values = 1.0 / (1.0 + np.exp(-(x - 3.0)))
return pa.StructArray.from_arrays([pa.array(sigmoid_values, type=pa.float32())], names=["values"])
The following remaps the Scalars:scalars input to read from custom:my_nested_scalar and selects the values field:
# Blue sigmoid:
# * source scalars from a nested struct using a selector to extract the "values" field
# * set the name and an explicit blue color via overrides
rr.SeriesLines(names="sigmoid (nested)", colors=[0, 0, 255]).visualizer(
mappings=[
VisualizerComponentMapping(
target="Scalars:scalars",
source_kind=ComponentSourceKind.SourceComponent,
source_component="custom:my_nested_scalar",
selector=".values",
),
]
),Providing default values providing-default-values
You can also force a visualizer to use a specific source kind. Setting the source to Default makes the visualizer
ignore any store data and use the view's default instead:
# Red sine:
# * set the name via an override
# * explicitly use the view's default for color
# * everything else uses the automatic component mappings, so it will pick up scalars from the store.
rr.SeriesLines(names="sine (store)").visualizer(
mappings=[
VisualizerComponentMapping(
target="SeriesLines:colors",
source_kind=ComponentSourceKind.Default,
),
]
),Full example full-example
The complete example logs three series to a single entity and configures each with a different component mapping strategy. This leads to the following visualizers for the /plot entity:
When the view is selected, the selection panel shows an overview of all configured visualizers: