Plotters#
Genesis provides real-time plotting recorders for visualizing simulation data during execution.
Available Plotters#
Plotter |
Description |
|---|---|
|
Matplotlib line plot (time series) |
|
Matplotlib image display |
MPLLinePlot#
Real-time line plots using Matplotlib:
import genesis as gs
gs.init()
scene = gs.Scene()
robot = scene.add_entity(gs.morphs.URDF(file="robot.urdf"))
scene.build()
# Plot joint positions over time
scene.start_recording(
data_func=lambda: robot.get_qpos()[:3], # First 3 joints
rec_options=gs.recorders.MPLLinePlot(
title="Joint Positions",
),
)
for i in range(1000):
scene.step()
scene.stop_recording()
Configuration#
gs.recorders.MPLLinePlot(
title="Plot Title", # Plot title
hz=30, # Update rate
)
MPLImagePlot#
Display images in real-time:
cam = scene.add_camera(res=(320, 240), pos=(3, 0, 2), lookat=(0, 0, 0.5))
scene.start_recording(
data_func=lambda: cam.render(rgb=True),
rec_options=gs.recorders.MPLImagePlot(
title="Camera View",
),
)
for i in range(500):
scene.step()
scene.stop_recording()
Multiple Recorders#
You can start multiple recorders for different data streams by calling start_recording multiple times or using the RecorderManager directly.
Performance Tips#
Reduce update rate: Use lower
hzfor complex plotsLimit data points: Use smaller
window_sizeUse async mode: Enable
async_mode=Truefor background updates
API Reference#
- class genesis.recorders.plotters.BasePlotter(manager: RecorderManager, options: BasePlotterOptions, data_func: Callable[[], T])[source]#
Bases:
Recorder- build()[source]#
Build the recorder, e.g. by initializing variables and creating widgets or file handles.
- process(data, cur_time)[source]#
Process each incoming data sample.
- Parameters:
data (Any) – The data to be processed.
cur_time (float) – The current time of the simulation.
- class genesis.recorders.plotters.LinePlotHelper(options: LinePlotterMixinOptions, data: dict[str, collections.abc.Sequence] | Sequence)[source]#
Bases:
objectHelper class that manages line plot data.
Use composition pattern.
- property history_length#
- property is_dict_data#
- property subplot_structure#
- class genesis.recorders.plotters.BasePyQtPlotter(manager: RecorderManager, options: BasePlotterOptions, data_func: Callable[[], T])[source]#
Bases:
BasePlotterBase class for PyQt based plotters.
- build()[source]#
Build the recorder, e.g. by initializing variables and creating widgets or file handles.
- cleanup()[source]#
Cleanup all resources, e.g. by closing widgets or files.
This method is called when recording is stopped by scene.stop_recording().
- property run_in_thread: bool#
Whether to run the recorder in a background thread.
Running in a background thread allows for processing data without blocking the main thread, so this is encouraged for most recorders (simply return True), but implementers should check that the recorder is thread-safe on all devices (threading on macOS tends to be less supported).
- class genesis.recorders.plotters.PyQtLinePlotter(manager: RecorderManager, options: BasePlotterOptions, data_func: Callable[[], T])[source]#
Bases:
BasePyQtPlotter- build()[source]#
Build the recorder, e.g. by initializing variables and creating widgets or file handles.
- class genesis.recorders.plotters.BaseMPLPlotter(manager: RecorderManager, options: BasePlotterOptions, data_func: Callable[[], T])[source]#
Bases:
BasePlotterBase class for matplotlib based plotters.
- build()[source]#
Build the recorder, e.g. by initializing variables and creating widgets or file handles.
- get_image_array()[source]#
Capture the plot image as a video frame.
- Returns:
image_array – The RGB image as a numpy array.
- Return type:
np.ndarray
- property run_in_thread: bool#
Whether to run the recorder in a background thread.
Running in a background thread allows for processing data without blocking the main thread, so this is encouraged for most recorders (simply return True), but implementers should check that the recorder is thread-safe on all devices (threading on macOS tends to be less supported).
- class genesis.recorders.plotters.MPLLinePlotter(manager: RecorderManager, options: BasePlotterOptions, data_func: Callable[[], T])[source]#
Bases:
BaseMPLPlotter- build()[source]#
Build the recorder, e.g. by initializing variables and creating widgets or file handles.
- class genesis.recorders.plotters.MPLImagePlotter(manager: RecorderManager, options: BasePlotterOptions, data_func: Callable[[], T])[source]#
Bases:
BaseMPLPlotterLive image viewer using matplotlib.
The image data should be an array-like object with shape (H, W), (H, W, 1), (H, W, 3), or (H, W, 4).
- class genesis.recorders.plotters.MPLVectorFieldPlotter(manager: RecorderManager, options: BasePlotterOptions, data_func: Callable[[], T])[source]#
Bases:
BaseMPLPlotterLive 3D vector field viewer: projects positions and vectors onto a 2D plane and plots arrows colored by magnitude.
The data_func should return an array of shape (N, 3) with the 3D vector at each position given in options.
See Also#
Recording & Playback - Recording overview
File Writers - File export