This example demonstrates how to log simple plots with the Rerun SDK. Charts can be created from 1-dimensional tensors, or from time-varying scalars.
BarChart
, Scalars
, SeriesPoints
, SeriesLines
, TextDocument
This example shows various plot types that you can create using Rerun. Common usecases for such plots would be logging losses or metrics over time, histograms, or general function plots.
The bar chart is created by logging the BarChart
archetype.
All other plots are created using the Scalars
archetype.
Each plot is created by logging scalars at different time steps (i.e., the x-axis).
Additionally, the plots are styled using the SeriesLines
and
SeriesPoints
archetypes respectively.
The visualizations in this example were created with the following Rerun code:
The log_bar_chart
function logs a bar chat.
It generates data for a Gaussian bell curve and logs it using BarChart
archetype.
def log_bar_chart() -> None:
# … existing code …
rr.log("bar_chart", rr.BarChart(y))
The log_parabola
function logs a parabola curve (sine and cosine functions) as a time series.
It first sets up a time sequence using timelines
, then calculates the y-value of the parabola at each time step, and logs it using Scalars
archetype.
It also adjusts the width and color of the plotted line based on the calculated y value using SeriesLines
archetype.
def log_parabola() -> None:
# Name never changes, log it only once.
rr.log("curves/parabola", rr.SeriesLines(name="f(t) = (0.01t - 3)³ + 1"), static=True)
# Log a parabola as a time series
for t in range(0, 1000, 10):
rr.set_time("frame_nr", sequence=t)
# … existing code …
rr.log(
"curves/parabola",
rr.Scalars(f_of_t),
rr.SeriesLines(width=width, color=color),
)
The log_trig
function logs sin and cos functions as time series. Sin and cos are logged with the same parent entity (i.e.,trig/{cos,sin}
) which will put them in the same view by default.
It first logs the styling properties of the sin and cos plots using SeriesLines
archetype.
Then, it iterates over a range of time steps, calculates the sin and cos values at each time step, and logs them using Scalars
archetype.
def log_trig() -> None:
# Styling doesn't change over time, log it once with static=True.
rr.log("trig/sin", rr.SeriesLines(color=[255, 0, 0], name="sin(0.01t)"), static=True)
rr.log("trig/cos", rr.SeriesLines(color=[0, 255, 0], name="cos(0.01t)"), static=True)
for t in range(0, int(tau * 2 * 100.0)):
rr.set_time("frame_nr", sequence=t)
sin_of_t = sin(float(t) / 100.0)
rr.log("trig/sin", rr.Scalars(sin_of_t))
cos_of_t = cos(float(t) / 100.0)
rr.log("trig/cos", rr.Scalars(cos_of_t))
The log_classification
function simulates a classification problem by logging a line function and randomly generated samples around that line.
It first logs the styling properties of the line plot using SeriesLines
archetype.
Then, it iterates over a range of time steps, calculates the y value of the line function at each time step, and logs it as a scalars using Scalars
archetype.
Additionally, it generates random samples around the line function and logs them using Scalars
and SeriesPoints
archetypes.
def log_classification() -> None:
# Log components that don't change only once:
rr.log("classification/line", rr.SeriesLines(colors=[255, 255, 0], widths=3.0), static=True)
for t in range(0, 1000, 2):
rr.set_time("frame_nr", sequence=t)
# … existing code …
rr.log("classification/line", rr.Scalars(f_of_t))
# … existing code …
rr.log("classification/samples", rr.Scalars(g_of_t), rr.SeriesPoints(colors=color, marker_sizes=marker_size))
To run this example, make sure you have the Rerun repository checked out and the latest SDK installed:
pip install --upgrade rerun-sdk # install the latest Rerun SDK
git clone git@github.com:rerun-io/rerun.git # Clone the repository
cd rerun
git checkout latest # Check out the commit matching the latest SDK release
Install the necessary libraries specified in the requirements file:
pip install -e examples/python/plots
To experiment with the provided example, simply execute the main Python script:
python -m plots # run the example
If you wish to customize it, explore additional features, or save it use the CLI with the --help
option for guidance:
python -m plots --help
send_columns
advanced-time-series--sendcolumnshttpsrefreruniodocspythonstablecommoncolumnarapirerunsendcolumnsLogging many scalars individually can be slow.
The send_columns
API can be used to log many scalars at once.
Check the Scalars
send_columns
snippet to learn more.