Module Visualization

This module implements functions to visualize all kind of objects from CommonRoad scenarios. Please refer to the Visualization Manual for detailed instructions and examples for using the API.

Drawing interface

class commonroad.visualization.drawable.IDrawable[source]

Interface for drawable types

abstract draw(renderer, draw_params)[source]

Draw the object

Parameters:
  • renderer (IRenderer) – Renderer to use for drawing

  • draw_params (Optional[BaseParam]) – optional parameters for plotting, overriding the parameters of the renderer

Return type:

None

Returns:

None

Drawing parameters

class commonroad.visualization.draw_params.BaseParam(time_begin=0, time_end=200, antialiased=True)[source]
time_begin: int = 0

First time step of the visualized time interval.

time_end: int = 200

Last time step of the visualized time interval.

antialiased: bool = True

Use anti-aliasing.

classmethod load(file_path, validate_types=True)[source]
save(file_path)[source]
class commonroad.visualization.draw_params.ShapeParams(time_begin=0, time_end=200, antialiased=True, opacity=1.0, facecolor='#1d7eea', edgecolor='#00478f', linewidth=0.5, zorder=20, draw_mesh=False)[source]
opacity: float = 1.0
facecolor: str = '#1d7eea'
edgecolor: str = '#00478f'
linewidth: float = 0.5
zorder: float = 20
draw_mesh: bool = False
class commonroad.visualization.draw_params.VehicleSignalParams(time_begin=0, time_end=200, antialiased=True, signal_radius=0.5, indicator=<factory>, braking=<factory>, horn=<factory>, bluelight=<factory>)[source]
signal_radius: float = 0.5
indicator: ShapeParams
braking: ShapeParams
horn: ShapeParams
bluelight: ShapeParams
class commonroad.visualization.draw_params.ArrowParams(time_begin=0, time_end=200, antialiased=True, linewidth=1.5, edgecolor='black', facecolor='black', width=0.8)[source]
linewidth: float = 1.5
edgecolor: str = 'black'
facecolor: str = 'black'
width: float = 0.8
class commonroad.visualization.draw_params.StateParams(time_begin=0, time_end=200, antialiased=True, draw_arrow=False, radius=0.5, scale_factor=0.3, linewidth=None, edgecolor='black', facecolor='black', zorder=25, arrow=<factory>)[source]
draw_arrow: bool = False
radius: float = 0.5
scale_factor: float = 0.3
linewidth: Optional[float] = None
edgecolor: Optional[str] = 'black'
facecolor: Optional[str] = 'black'
zorder: float = 25
arrow: ArrowParams
class commonroad.visualization.draw_params.OccupancyParams(time_begin=0, time_end=200, antialiased=True, draw_occupancies=False, shape=<factory>, uncertain_position=<factory>)[source]
draw_occupancies: bool = False
shape: ShapeParams
uncertain_position: ShapeParams
class commonroad.visualization.draw_params.HistoryParams(time_begin=0, time_end=200, antialiased=True, draw_history=False, steps=5, step_size=1, fade_color=0.1, basecolor='#ffe119', occupancy=<factory>)[source]

Draw the history of an object with fading colors.

draw_history: bool = False
steps: int = 5
step_size: int = 1
fade_color: float = 0.1
basecolor: str = '#ffe119'
occupancy: ShapeParams
class commonroad.visualization.draw_params.StaticObstacleParams(time_begin=0, time_end=200, antialiased=True, occupancy=<factory>)[source]
occupancy: OccupancyParams
class commonroad.visualization.draw_params.EnvironmentObstacleParams(time_begin=0, time_end=200, antialiased=True, occupancy=<factory>)[source]
occupancy: OccupancyParams
class commonroad.visualization.draw_params.TrafficLightParams(time_begin=0, time_end=200, antialiased=True, draw_traffic_lights=True, red_color='red', yellow_color='#feb609', green_color='#00aa16', red_yellow_color='#fe4009ff', show_label=False, scale_factor=1.0, zorder=30)[source]
draw_traffic_lights: bool = True
red_color: str = 'red'

Color of the red phase

yellow_color: str = '#feb609'

Color of the yellow phase

green_color: str = '#00aa16'

Color of the green phase

red_yellow_color: str = '#fe4009ff'

Color of the red-yellow phase

show_label: bool = False

Show id of the traffic light

scale_factor: float = 1.0
zorder: float = 30
class commonroad.visualization.draw_params.TrafficSignParams(time_begin=0, time_end=200, antialiased=True, draw_traffic_signs=False, show_traffic_signs=None, speed_limit_unit='auto', show_label=False, scale_factor=1.0, zorder=30)[source]
draw_traffic_signs: bool = False

Enable drawing of traffic signs

show_traffic_signs: Optional[List[int]] = None

Limit traffic signs to a list of IDs, or None to include all IDs.

speed_limit_unit: str = 'auto'

Select mph or kmh as unit of the speed limit. Choose “auto” to determine based on the country.

show_label: bool = False

Show id of the traffic sign

scale_factor: float = 1.0
zorder: float = 30
class commonroad.visualization.draw_params.IntersectionParams(time_begin=0, time_end=200, antialiased=True, draw_intersections=False, draw_incoming_lanelets=True, incoming_lanelets_color='#3ecbcf', draw_crossings=True, crossings_color='#b62a55', draw_successors=True, successors_left_color='#ff00ff', successors_straight_color='blue', successors_right_color='#ccff00', show_label=False)[source]
draw_intersections: bool = False
draw_incoming_lanelets: bool = True
incoming_lanelets_color: str = '#3ecbcf'
draw_crossings: bool = True
crossings_color: str = '#b62a55'
draw_successors: bool = True
successors_left_color: str = '#ff00ff'
successors_straight_color: str = 'blue'
successors_right_color: str = '#ccff00'
show_label: bool = False

Show the ID of the intersection

class commonroad.visualization.draw_params.LaneletParams(time_begin=0, time_end=200, antialiased=True, left_bound_color='#555555', right_bound_color='#555555', center_bound_color='#dddddd', unique_colors=False, draw_stop_line=True, stop_line_color='#ffffff', draw_line_markings=True, draw_left_bound=True, draw_right_bound=True, draw_center_bound=True, draw_border_vertices=False, draw_start_and_direction=True, colormap_tangent=False, show_label=False, draw_linewidth=0.5, fill_lanelet=True, facecolor='#c7c7c7')[source]
left_bound_color: str = '#555555'
right_bound_color: str = '#555555'
center_bound_color: str = '#dddddd'
unique_colors: bool = False
draw_stop_line: bool = True
stop_line_color: str = '#ffffff'
draw_line_markings: bool = True
draw_left_bound: bool = True
draw_right_bound: bool = True
draw_center_bound: bool = True
draw_border_vertices: bool = False
draw_start_and_direction: bool = True

Show a triangle at the beginning of the lanelet, pointing in the driving direction.

colormap_tangent: bool = False

Apply a colormap to the center line of the lanelet, according the tangent angle.

show_label: bool = False

Show the ID of the lanelet.

draw_linewidth: float = 0.5
fill_lanelet: bool = True

Fill the lanelet with a solid color.

facecolor: str = '#c7c7c7'

Fill color of the lanelet.

class commonroad.visualization.draw_params.LaneletNetworkParams(time_begin=0, time_end=200, antialiased=True, kwargs_traffic_light_signs=<factory>, draw_ids=None, lanelet=<factory>, intersection=<factory>, relative_angle=0.0, traffic_sign=<factory>, traffic_light=<factory>)[source]
kwargs_traffic_light_signs: Dict[str, Any]
draw_ids: Optional[List[int]] = None

Limit lanelets to a list of IDs, or None to include all IDs.

lanelet: LaneletParams

Options for lanelet drawing.

intersection: IntersectionParams

Options for intersection drawing.

relative_angle: float = 0.0

Offset angle for tangent colormap. See LaneletParams.colormap_tangent

traffic_sign: TrafficSignParams

Options for traffic sign drawing.

traffic_light: TrafficLightParams

Options for traffic light drawing.

class commonroad.visualization.draw_params.TrajectoryParams(time_begin=0, time_end=200, antialiased=True, draw_trajectory=True, facecolor='k', draw_continuous=False, line_width=0.17, unique_colors=False, shape=<factory>, zorder=24)[source]
draw_trajectory: bool = True
facecolor: str = 'k'
draw_continuous: bool = False

Draw trajectories as a continuous line instead of dots.

line_width: float = 0.17
unique_colors: bool = False

Use unique colors for each of the trajectories points.

shape: ShapeParams

Parameters for shapes of uncertain position.

zorder: float = 24
class commonroad.visualization.draw_params.InitialStateParams(time_begin=0, time_end=200, antialiased=True, label_zorder=35, label='', state=<factory>)[source]
label_zorder: float = 35
label: str = ''
state: StateParams
class commonroad.visualization.draw_params.PlanningProblemParams(time_begin=0, time_end=200, antialiased=True, initial_state=<factory>, goal_region=<factory>, lanelet=<factory>)[source]
initial_state: InitialStateParams
goal_region: OccupancyParams
lanelet: LaneletParams

Goal lanelet parameters

class commonroad.visualization.draw_params.PlanningProblemSetParams(time_begin=0, time_end=200, antialiased=True, draw_ids=None, planning_problem=<factory>)[source]
draw_ids: Optional[List[int]] = None

Limit planning problems to a list of IDs, or None to include all IDs.

planning_problem: PlanningProblemParams
class commonroad.visualization.draw_params.VehicleShapeParams(time_begin=0, time_end=200, antialiased=True, direction=<factory>, occupancy=<factory>)[source]
direction: ShapeParams

Options for visualizing the direction indicator of the vehicle shape.

occupancy: OccupancyParams

Options for visualizing the vehicle’s occupancy in the current time step.

class commonroad.visualization.draw_params.DynamicObstacleParams(time_begin=0, time_end=200, antialiased=True, draw_shape=True, draw_icon=False, draw_direction=False, draw_bounding_box=True, show_label=False, draw_signals=True, draw_initial_state=False, vehicle_shape=<factory>, signals=<factory>, state=<factory>, history=<factory>, occupancy=<factory>, trajectory=<factory>)[source]
draw_shape: bool = True
draw_icon: bool = False

Draw a type-dependent icon (if available) instead of the primitive geometric shape.

draw_direction: bool = False

Draw the direction indicator of the dynamic obstacle.

draw_bounding_box: bool = True
show_label: bool = False

Show the ID of the dynamic obstacle.

draw_signals: bool = True

Visualize the dynamic obstacle signals like indicator or braking lights.

draw_initial_state: bool = False

Draw the initial state of the dynamic obstacle.

vehicle_shape: VehicleShapeParams

Options for visualizing the vehicle in the current time step.

signals: VehicleSignalParams

Options for visualizing the vehicle signals.

state: StateParams

Options for visualizing the vehicle states within [time_begin, time_end].

history: HistoryParams

Options for visualizing the vehicle occupancy history with fading colors.

occupancy: OccupancyParams

Options for visualizing the vehicle occupancy in future time steps.

trajectory: TrajectoryParams

Options for visualizing the vehicle trajectory in future time steps.

class commonroad.visualization.draw_params.PhantomObstacleParams(time_begin=0, time_end=200, antialiased=True, draw_shape=True, draw_icon=False, draw_direction=False, draw_bounding_box=True, show_label=False, zorder=20, draw_signals=True, vehicle_shape=<factory>, signals=<factory>, draw_initial_state=False, state=<factory>, history=<factory>, occupancy=<factory>, trajectory=<factory>)[source]
draw_shape: bool = True
draw_icon: bool = False
draw_direction: bool = False
draw_bounding_box: bool = True
show_label: bool = False
zorder: float = 20
draw_signals: bool = True
vehicle_shape: VehicleShapeParams
signals: VehicleSignalParams
draw_initial_state: bool = False
state: StateParams
history: HistoryParams
occupancy: OccupancyParams
trajectory: TrajectoryParams
class commonroad.visualization.draw_params.MPDrawParams(time_begin=0, time_end=200, antialiased=True, axis_visible=True, shape=<factory>, dynamic_obstacle=<factory>, static_obstacle=<factory>, phantom_obstacle=<factory>, environment_obstacle=<factory>, trajectory=<factory>, lanelet_network=<factory>, traffic_light=<factory>, traffic_sign=<factory>, occupancy=<factory>, state=<factory>, planning_problem=<factory>, planning_problem_set=<factory>, initial_state=<factory>, goal_region=<factory>)[source]
axis_visible: bool = True

Enable axes for matplotlib.

shape: ShapeParams
dynamic_obstacle: DynamicObstacleParams
static_obstacle: StaticObstacleParams
phantom_obstacle: PhantomObstacleParams
environment_obstacle: EnvironmentObstacleParams
trajectory: TrajectoryParams
lanelet_network: LaneletNetworkParams
traffic_light: TrafficLightParams
traffic_sign: TrafficSignParams
occupancy: OccupancyParams
state: StateParams
planning_problem: PlanningProblemParams
planning_problem_set: PlanningProblemSetParams
initial_state: InitialStateParams
goal_region: OccupancyParams

Renderers

Inheritance diagram of commonroad.visualization.renderer.IRenderer, commonroad.visualization.mp_renderer.MPRenderer

IRenderer provides the interface that all renderer implementations must adhere to. Currently, the following renderers are implemented:

  • MPRenderer: A renderer using matplotlib as backend

IRenderer class

class commonroad.visualization.renderer.IRenderer[source]

Interface for renderers

abstract draw_scenario(obj, draw_params=None)[source]
Parameters:
  • obj – object to be plotted

  • draw_params – optional parameters for plotting, overriding the parameters of the renderer

Returns:

None

abstract draw_static_obstacle(obj, draw_params=None)[source]
Parameters:
  • obj – object to be plotted

  • draw_params – optional parameters for plotting, overriding the parameters of the renderer

Returns:

None

abstract draw_dynamic_obstacle(obj, draw_params=None)[source]
Parameters:
  • obj – object to be plotted

  • draw_params – optional parameters for plotting, overriding the parameters of the renderer

Returns:

None

abstract draw_phantom_obstacle(obj, draw_params=None)[source]
Parameters:
  • obj – object to be plotted

  • draw_params – optional parameters for plotting, overriding the parameters of the renderer

Returns:

None

abstract draw_environment_obstacle(obj, draw_params=None)[source]
Parameters:
  • obj – object to be plotted

  • draw_params – optional parameters for plotting, overriding the parameters of the renderer

Returns:

None

abstract draw_trajectory(obj, draw_params=None)[source]
Parameters:
  • obj – object to be plotted

  • draw_params – optional parameters for plotting, overriding the parameters of the renderer

Returns:

None

abstract draw_trajectories(obj, draw_params=None)[source]
abstract draw_polygon(vertices, draw_params=None)[source]

Draws a polygon shape

Parameters:
  • vertices – vertices of the polygon

  • draw_params – optional parameters for plotting, overriding the parameters of the renderer

Returns:

None

abstract draw_rectangle(vertices, draw_params=None)[source]

Draws a rectangle shape

Parameters:
  • vertices – vertices of the rectangle

  • draw_params – parameters for plotting given by a nested dict that recreates the structure of an object, which allows for differentiation of plotting styles depending on the call stack

Returns:

None

abstract draw_ellipse(center, radius_x, radius_yt, draw_params=None)[source]

Draws a circle shape

Parameters:
  • ellipse – center position of the ellipse

  • radius_x – radius of the ellipse along the x-axis

  • radius_y – radius of the ellipse along the y-axis

  • draw_params – parameters for plotting given by a nested dict that recreates the structure of an object, which allows for differentiation of plotting styles depending on the call stack

Returns:

None

abstract draw_state(state, draw_params=None)[source]

Draws a state as an arrow of its velocity vector

Parameters:
  • state – state to be plotted

  • draw_params – optional parameters for plotting, overriding the parameters of the renderer

Returns:

None

abstract draw_lanelet_network(obj, draw_params=None)[source]

Draws a lanelet network

Parameters:
  • obj – object to be plotted

  • draw_params – parameters for plotting given by a nested dict that recreates the structure of an object, which allows for differentiation of plotting styles depending on the call stack

Returns:

None

abstract draw_goal_region(obj, draw_params=None)[source]

Draw goal states from goal region

Parameters:
  • obj – object to be plotted

  • draw_params – optional parameters for plotting, overriding the parameters of the renderer

Returns:

None

abstract draw_planning_problem(obj, draw_params=None)[source]

Draw initial state and goal region of the planning problem

Parameters:
  • obj – object to be plotted

  • draw_params – optional parameters for plotting, overriding the parameters of the renderer

Returns:

None

abstract draw_planning_problem_set(obj, draw_params=None)[source]

Draws all or selected planning problems from the planning problem set. Planning problems can be selected by providing IDs in drawing_params[planning_problem_set][draw_ids]

Parameters:
  • obj – object to be plotted

  • draw_params – optional parameters for plotting, overriding the parameters of the renderer

Returns:

None

abstract draw_initital_state(obj, draw_params=None)[source]

Draw initial state with label

Parameters:
  • obj – object to be plotted

  • draw_params – optional parameters for plotting, overriding the parameters of the renderer

Returns:

None

abstract draw_goal_state(obj, draw_params=None)[source]

Draw goal states

Parameters:
  • obj – object to be plotted

  • draw_params – optional parameters for plotting, overriding the parameters of the renderer

Returns:

None

abstract draw_traffic_light_sign(obj, draw_params=None)[source]

Draw traffic sings and lights

Parameters:
  • obj – object to be drawn

  • draw_params – optional parameters for plotting, overriding the parameters of the renderer

Returns:

None

MPRenderer class

class commonroad.visualization.mp_renderer.MPRenderer(draw_params=None, plot_limits=None, ax=None, figsize=None, focus_obstacle=None)[source]

Renderer with matplotlib backend

property plot_limits
property plot_limits_focused

plot limits centered around focus_obstacle_id defined in draw_params

add_callback(event, func)[source]
draw_list(drawable_list, draw_params=None)[source]

Simple wrapper to draw a list of drawable objects

Parameters:
  • drawable_list (List[IDrawable]) – Objects to draw

  • draw_params (Union[MPDrawParams, List[Optional[BaseParam]], None]) – optional parameters for plotting, overriding the parameters of the renderer

Return type:

None

Returns:

None

clear(keep_static_artists=False)[source]

Clears the internal drawing buffer

Return type:

None

Returns:

None

remove_dynamic()[source]

Remove the dynamic objects from their current axis

Return type:

None

Returns:

None

render_dynamic()[source]

Only render dynamic objects from buffer

Return type:

List[Artist]

Returns:

List of drawn object’s artists

render_static()[source]

Only render static objects from buffer

Return type:

List[Artist]

Returns:

List of drawn object’s artists

render(show=False, filename=None, keep_static_artists=False)[source]

Render all objects from buffer

Parameters:
  • show (bool) – Show the resulting figure

  • filename (str) – If provided, saves the figure to the provided file

Return type:

List[Artist]

Returns:

List of drawn object’s artists

create_video(obj_lists, file_path, delta_time_steps=1, plotting_horizon=0, draw_params=None, fig_size=None, dt=None, dpi=120, progress=True, callback=None)[source]

Creates a video of one or multiple CommonRoad objects in mp4, gif, or avi format.

Parameters:
  • obj_lists (List[IDrawable]) – list of objects to be plotted.

  • file_path (str) – filename of generated video (ends on .mp4/.gif/.avi, default mp4, when nothing is specified)

  • delta_time_steps (int) – plot every delta_time_steps time steps of scenario

  • plotting_horizon (int) – time steps of prediction plotted in each frame

  • draw_params (Union[List[Optional[BaseParam]], BaseParam, None]) – optional parameters for plotting, overriding the parameters of the renderer

  • fig_size (Optional[list]) – size of the video

  • dt (Optional[int]) – time step between frames in ms

  • dpi (int) – resolution of the video

  • progress (bool) – Show a progress bar.

  • callback (Optional[Callable[[Figure, Axes, int], None]]) – Callback called after drawing each frame. Parameters passed to the callback are the matplotlib figure and axes object, and the frame number.

Return type:

None

Returns:

None

draw_scenario(obj, draw_params=None)[source]
Parameters:
  • obj (Scenario) – object to be plotted

  • draw_params (Optional[MPDrawParams]) – optional parameters for plotting, overriding the parameters of the renderer

Return type:

None

Returns:

None

draw_static_obstacle(obj, draw_params=None)[source]
Parameters:
Return type:

None

Returns:

None

draw_dynamic_obstacle(obj, draw_params)[source]
Parameters:
Return type:

None

Returns:

None

draw_phantom_obstacle(obj, draw_params=None)[source]
Parameters:
  • obj (PhantomObstacle) – object to be plotted

  • draw_params (Union[PhantomObstacleParams, MPDrawParams, None]) – optional parameters for plotting, overriding the parameters of the renderer

Return type:

None

Returns:

None

draw_environment_obstacle(obj, draw_params=None)[source]
Parameters:
  • obj (EnvironmentObstacle) – object to be plotted

  • draw_params (Union[EnvironmentObstacleParams, MPDrawParams, None]) – optional parameters for plotting, overriding the parameters of the renderer

Return type:

None

Returns:

None

draw_trajectory(obj, draw_params=None)[source]
Parameters:
Return type:

None

Returns:

None

draw_trajectories(obj, draw_params=None)[source]
Return type:

None

draw_polygon(vertices, draw_params=None)[source]

Draws a polygon shape

Parameters:
  • vertices – vertices of the polygon

  • draw_params (Union[ShapeParams, MPDrawParams, None]) – optional parameters for plotting, overriding the parameters of the renderer

Return type:

None

Returns:

None

draw_rectangle(vertices, draw_params=None)[source]

Draws a rectangle shape

Parameters:
  • vertices (ndarray) – vertices of the rectangle

  • draw_params (Union[ShapeParams, MPDrawParams, None]) – parameters for plotting given by a nested dict that recreates the structure of an object,

Return type:

None

Returns:

None

draw_ellipse(center, radius_x, radius_y, draw_params)[source]

Draws a circle shape

Parameters:
  • ellipse – center position of the ellipse

  • radius_x (float) – radius of the ellipse along the x-axis

  • draw_params (Union[ShapeParams, MPDrawParams, None]) – parameters for plotting given by a nested dict that recreates the structure of an object,

Return type:

None

Returns:

None

draw_state(state, draw_params=None)[source]

Draws a state as an arrow of its velocity vector

Parameters:
Return type:

None

Returns:

None

draw_lanelet_network(obj, draw_params=None)[source]

Draws a lanelet network

Parameters:
Return type:

None

Returns:

None

draw_planning_problem_set(obj, draw_params=None)[source]

Draws all or selected planning problems from the planning problem set. Planning problems can be selected by providing IDs in`drawing_params[planning_problem_set][draw_ids]`

Parameters:
Return type:

None

Returns:

None

draw_planning_problem(obj, draw_params=None)[source]

Draw initial state and goal region of the planning problem

Parameters:
Return type:

None

Returns:

None

draw_initital_state(obj, draw_params=None)[source]

Draw initial state with label

Parameters:
Return type:

None

Returns:

None

draw_goal_region(obj, draw_params=None)[source]

Draw goal states from goal region

Parameters:
Return type:

None

Returns:

None

draw_goal_state(obj, draw_params=None)[source]

Draw goal states

Parameters:
Return type:

None

Returns:

None

draw_traffic_light_sign(obj, draw_params=None)[source]

Draw traffic sings and lights

Parameters:
Returns:

None