Use a time series view to plot numeric signals over time. It is useful for spotting trends, spikes, and differences between signals, such as sensor readings, model scores, or tracking errors.
See the TimeSeriesView reference for properties and examples.
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.
Logging multiple scalars to the same entity also makes .rrd files smaller than logging each scalar to its own entity.
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. For styling and axes, see Customize plots. For how to log the data, see Logging custom data. Component mappings has scalar examples of selectors for nested data and default values.
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:
# Green cosine:
# * source scalars from the custom component
# "custom:my_custom_scalar"
# * set the name via an override
# * everything else uses the automatic component mappings,
# so it will pick up colors from the view default.
rr.SeriesLines(names="cosine (custom)").visualizer(
mappings=[
# Map scalars to the custom component.
VisualizerComponentMapping(
target="Scalars:scalars",
source_kind=ComponentSourceKind.SourceComponent,
# Map from custom component
source_component="custom:my_custom_scalar",
),
]
),Add data by dragging components
You can set up this mapping interactively instead of via the blueprint API: drag a component from the streams panel onto a time series view.
If the component has a compatible (numeric) datatype, a new SeriesLines visualizer is added that remaps Scalars:scalars from it.
Non-numeric components (e.g. a string) are rejected, as is dropping a component that the view already plots.
Complete scalar mapping 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:
Show a subset of plotted series
When you log several values in one Scalars batch, such as the joint positions of a robot arm, each value is plotted as its own series in a TimeSeriesView.
You can show only some of them from the Viewer or from code.
In the Viewer
Click a series in the plot legend to hide or show it. The Viewer stores this choice in the blueprint.
From code
Set visible_series of SeriesLines as a blueprint override.
It takes one boolean per series, in the order of the values in the batch.
If the list is shorter than the number of series, its last value is repeated.
Hidden series stay in the legend, so you can click them to show them again.
For series drawn as points, use SeriesPoints instead.
For other plot settings, see Customize plots.
"""Show one series of a multi-value `Scalars` batch."""
from __future__ import annotations
import math
import rerun as rr
import rerun.blueprint as rrb
rr.init("rerun_example_visible_series", spawn=True)
for t in range(50):
rr.set_time("step", sequence=t)
positions = [math.sin(t / 10 + j) for j in range(7)]
rr.log("robot/joint_positions", rr.Scalars(positions))
# Show only the third joint
rr.send_blueprint(
rrb.TimeSeriesView(
overrides={
"robot/joint_positions": rr.SeriesLines(
visible_series=[False, False, True, False, False, False, False]
),
},
),
)
Visualize fixed-window plots
The TimeSeriesView supports direct manipulation of the visible time range. This allows you to create a plot that only shows a fixed window of data.
Visible time ranges also work in 2D and 3D views, for example for trails. See Visible time ranges for the shared settings, per-entity ranges, and linked time axes.
Pass a VisibleTimeRange to time_ranges.
See How VisibleTimeRange works for timelines and boundary types.
Example syntax
fixed_window_plot = rrb.TimeSeriesView(
origin="/sensors",
time_ranges=rrb.VisibleTimeRange(
timeline="time",
start=rrb.TimeRangeBoundary.cursor_relative(seconds=-5.0),
end=rrb.TimeRangeBoundary.cursor_relative(),
),
)Complete fixed-window example
For a complete working example, you can run the following code:
#!/usr/bin/env python3
"""A live plot of a random walk using a scrolling fixed window size."""
from __future__ import annotations
import time
import numpy as np
import rerun as rr # pip install rerun-sdk
import rerun.blueprint as rrb
rr.init("rerun_example_fixed_window_plot", spawn=True)
rr.send_blueprint(
rrb.TimeSeriesView(
origin="random_walk",
time_ranges=rrb.VisibleTimeRange(
"time",
start=rrb.TimeRangeBoundary.cursor_relative(seconds=-5.0),
end=rrb.TimeRangeBoundary.cursor_relative(),
),
),
)
rng = np.random.default_rng(0)
cur_time = time.time()
value = 0.0
while True:
cur_time += 0.01
sleep_for = cur_time - time.time()
if sleep_for > 0:
time.sleep(sleep_for)
value += rng.normal()
rr.set_time("time", timestamp=cur_time)
rr.log("random_walk", rr.Scalars(value))
Alternatively, you can check out a more full-featured example with multiple plot windows here.
Additional notes
- Any time you log data, it is automatically timestamped on the
log_timetimeline (and onlog_tick, if enabled).
Customize plots
For histograms and spectra, use a bar chart view. For XY plots, use a 2D view.
Series names, colors, and line widths
Log SeriesLines (or SeriesPoints for markers) to the same entity as your Scalars.
Log the style as static, since it does not change over time:
"""Log a scalar over time."""
from math import cos, sin, tau
import rerun as rr
rr.init("rerun_example_series_line_style", spawn=True)
# Set up plot styling:
# They are logged as static as they don't change over time and apply to
# all timelines.
# Log two lines series under a shared root so that they show in the same
# plot by default.
rr.log(
"trig/sin",
rr.SeriesLines(colors=[255, 0, 0], names="sin(0.01t)", widths=2),
static=True,
)
rr.log(
"trig/cos",
rr.SeriesLines(colors=[0, 255, 0], names="cos(0.01t)", widths=4),
static=True,
)
# Log the data on a timeline called "step".
for t in range(int(tau * 2 * 100.0)):
rr.set_time("step", sequence=t)
rr.log("trig/sin", rr.Scalars(sin(float(t) / 100.0)))
rr.log("trig/cos", rr.Scalars(cos(float(t) / 100.0)))
If you log several scalars in one batch, pass one name, color, and width per series. To hide some of the series, see Show a subset of plotted series.
You can also set these values for a whole view with blueprint defaults, or per entity with overrides. See Customize views.
Axis range and legend
Use ScalarAxis for the Y axis, and PlotLegend for the legend:
axis_plot = rrb.TimeSeriesView(
origin="/sensors",
axis_y=rrb.ScalarAxis(range=(-1.0, 1.0), zoom_lock=True),
plot_legend=rrb.PlotLegend(visible=False),
)The Y axis is always linear.
There is no logarithmic axis yet: plot log10 of your values instead.
See missing features.
To set the X (time) axis window, see Scrolling plots and the time axis. To pan and zoom several plots together, see Link the time axis of several plots.
Error bands and uncertainty
Measurements logs values together with their variances.
The time series view draws each series with a band of one standard deviation around it.
Measurements is unstable: its data format may change in future releases.
"""Log scalar measurements with variances over time."""
import math
import rerun as rr
rr.init("rerun_example_measurements_simple", spawn=True)
# Two parallel pressure sensors (in Pa), each with slowly drifting variance.
for step in range(64):
rr.set_time("step", sequence=step)
pressures = [
101_325.0 + 50.0 * math.sin(step / 10.0),
101_300.0 + 30.0 * math.cos(step / 8.0),
]
variances = [
100.0 + 25.0 * math.sin(step / 7.0),
80.0 + 15.0 * math.cos(step / 11.0),
]
rr.log(
"pressure",
rr.Measurements(values=pressures, variances=variances, units="Pa"),
)
For spatial uncertainty, see 2D covariance ellipses and 3D covariance ellipsoids.
Plot data that was not logged as Scalars
You can plot any numeric component, for example from MCAP files or from AnyValues.
See Plot any scalar.
Select visualizers
You can draw scalar data as lines, points, or both. See Select visualizers for the blueprint example.