esc
Start typing to search the docs
Navigate Open

Customize plots

This page collects common questions about plots in the TimeSeriesView and the BarChartView.

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:

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, or to link the time axis of several plots, see Show trails, history, and sliding time windows.

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"),
    )

See Visualize uncertainty for 2D and 3D uncertainty.

XY plots (Y against something other than time)

The X axis of a time series view is always a timeline. To plot Y against another value, for example a trajectory or a phase plot, log the points as Points2D or LineStrips2D and show them in a 2D view:

import numpy as np
import rerun as rr

rr.init("rerun_example_xy_plot", spawn=True)

x = np.linspace(-3.0, 3.0, 200)
y = np.sin(x) * x
rr.log("xy_plot", rr.LineStrips2D([np.column_stack([x, -y])]))

The 2D view has its Y axis pointing down, like images, so flip the sign of Y.

Histograms

Use BarChart with precomputed bins. abscissa sets the left edge of each bar, and widths sets the width of each bin, in X axis units:

import numpy as np
import rerun as rr

rr.init("rerun_example_histogram", spawn=True)

samples = np.random.default_rng(0).normal(size=10_000)
counts, edges = np.histogram(samples, bins=50)
rr.log(
    "histogram",
    rr.BarChart(counts, abscissa=edges[:-1], widths=np.diff(edges)),
)

values can be any numeric type.

Spectra and other vectors that change over time

To show a vector per time step, such as an FFT spectrum, a forecast horizon, or a lidar scan line, log a new BarChart (or a LineStrips2D in a 2D view) on every time step. Then move the time cursor to see the vector at that time.

for step, spectrum in enumerate(spectra):
    rr.set_time("step", sequence=step)
    rr.log("spectrum", rr.BarChart(spectrum, abscissa=frequencies))

There is no waterfall or spectrogram view yet. As a workaround, log the spectrogram as an Image (one column per time step), or as a Tensor. See missing features.

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.