PyPlot (matplotlib)

class roboticstoolbox.backends.PyPlot.PyPlot[source]

Bases: Connector

Graphical backend using matplotlib

matplotlib is a common and highly portable graphics library for Python, but has relatively limited 3D capability.

Example:

1import roboticstoolbox as rtb
2
3robot = rtb.models.DH.Panda()  # create a robot
4
5pyplot = rtb.backends.PyPlot()  # create a PyPlot backend
6pyplot.add(robot)              # add the robot to the backend
7robot.q = robot.qz             # set the robot configuration
8pyplot.step()                  # update the backend and graphical view

Note

PyPlot is the default backend, and robot.plot(q) effectively performs lines 7-8 above.

launch(name=None, fig=None, limits=None, **kwargs)[source]

Launch a graphical interface

`env = launch()` creates a blank 3D matplotlib figure and returns a reference to the backend.

step(dt=0.05)[source]

Update the graphical scene

Parameters:

dt (int, optional) – time step in seconds, defaults to 50 (0.05 s)

env.step(args) triggers an update of the 3D scene in the matplotlib window referenced by env.

Note

  • Each robot in the scene is updated based on their control type (position, velocity, acceleration, or torque).

  • Upon acting, the other three of the four control types will be updated in the internal state of the robot object.

  • The control type is defined by the robot object, and not all robot objects support all control types.

  • Execution is blocked for the specified interval

reset()[source]

Reset the graphical scene

env.reset() triggers a reset of the 3D scene in the matplotlib window referenced by env. It is restored to the original state defined by launch().

restart()[source]

Restart the graphics display

env.restart() triggers a restart of the matplotlib view referenced by env. It is closed and relaunched to the original state defined by launch().

close()[source]

env.close() gracefully closes the matplotlib window referenced by env.

add(ob, readonly=False, display=True, jointaxes=True, jointlabels=False, eeframe=True, shadow=True, name=True, options=None)[source]

Add a robot to the graphical scene

Parameters:
  • ob (DHRobot or EllipsePlot) – The object to add to the plot (robot or ellipse)

  • readonly (bool, optional) – Do not update the state of the object (i.e. display not simulate), defaults to False

  • display (bool, optional) – Display the object, defaults to True

  • jointaxes (bool, optional) – Show the joint axes of the robot with arrows, defaults to True

  • eeframe (bool, optional) – Show the end-effector frame of the robot, defaults to True

  • shadow (bool, optional) – Display a shadow of the robot on the x-y gound plane, defaults to True

  • name (bool, optional) – Display the name of the robot, defaults to True

id = env.add(robot) adds the robot to the graphical

environment.

Note

  • robot must be of an appropriate class.

  • Adds the robot object to a list of robots which will be updated when the step() method is called.

remove(id)[source]

Remove a robot or shape from the graphical scene

Parameters:
  • id (class:DHRobot, class:roboticstoolbox.backends.VPython.graphics_robot.GraphicalRobot) – The id of the robot to remove. Can be either the DHLink or GraphicalRobot

  • fig_num (int, optional) – The canvas index to delete the robot from, defaults to the initial one

Raises:
  • ValueError – Figure number must be between 0 and total number of canvases

  • TypeError – Input must be a DHLink or GraphicalRobot

env.remove(robot) removes the robot from the graphical

environment.

hold()[source]

hold() keeps the plot open i.e. stops the plot from closing once the main script has finished.

getframe()[source]
class roboticstoolbox.backends.PyPlot.PyPlot2[source]

Bases: Connector

launch(name=None, limits=None, **kwargs)[source]

env = launch() launchs a blank 2D matplotlib figure

step(dt=0.05)[source]

state = step(args) triggers the external program to make a time step of defined time updating the state of the environment as defined by the robot’s actions.

The will go through each robot in the list and make them act based on their control type (position, velocity, acceleration, or torque). Upon acting, the other three of the four control types will be updated in the internal state of the robot object. The control type is defined by the robot object, and not all robot objects support all control types.

reset()[source]

state = reset() triggers the external program to reset to the original state defined by launch

restart()[source]

state = restart() triggers the external program to close and relaunch to thestate defined by launch

close()[source]

close() closes the plot

add(ob, readonly=False, display=True, eeframe=True, name=False, **kwargs)[source]

id = add(robot) adds the robot to the external environment. robot must be of an appropriate class. This adds a robot object to a list of robots which will act upon the step() method being called.

remove()[source]

id = remove(robot) removes the robot to the external environment.

hold()[source]

hold() keeps the plot open i.e. stops the plot from closing once the main script has finished.