Plotters#
Genesis 提供实时绘图 recorders,用于在执行期间可视化仿真数据。
可用的 Plotters#
Plotter |
Description |
|---|---|
|
Matplotlib 折线图(时间序列) |
|
Matplotlib 图像显示 |
MPLLinePlot#
使用 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()
配置#
gs.recorders.MPLLinePlot(
title="Plot Title", # 绘图标题
hz=30, # 更新率
)
MPLImagePlot#
实时显示图像:
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#
您可以通过多次调用 start_recording 或直接使用 RecorderManager 来为不同的数据流启动多个 recorders。
性能提示#
降低更新率:对复杂绘图使用较低的
hz限制数据点:使用较小的
window_size使用异步模式:启用
async_mode=True进行后台更新
API 参考#
另请参阅#
记录与回放 - 录制概述
File Writers - 文件导出