pyplot._pyplot
ΒΆ
Copyright (C) 2025 Murilo Marques Marinho (www.murilomarinho.info)
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Author: Murilo M. Marinho
Module ContentsΒΆ
FunctionsΒΆ
An aggregator for all plot functions related to dqrobotics. Currently, supports |
|
Implementing the pyplot valid options of https://github.com/dqrobotics/matlab/blob/master/%40DQ/plot.m the particular plotting functions did not inherit from these implementations and are an informed attempt of using DQ operators to plot the objects. |
|
Draw a plane representing the DQ pi_dq. In this plot, the normal will be represented by the local z-axis of the plane and the plane will span in its local x-y axis. |
|
Draw a serial manipulator at a given joint configuration q. Each joint transformation will be connected by a line with spec line_color and width linewidth. |
|
Draw a reference frame at a given pose x. |
|
Draw a line representing the DQ l_dq. |
|
Draw a sphere of a given |
|
This internal function is used to draw cylinders, for now, for DQ_SerialManipulators. The cylinderβs height is through its z-axis, and it spans from -height_z/2 to +height_z/2. |
|
This internal function currently does not seem to exist in the implementation of dqrobotics. It will be replaced when itβs available. Iβm basing this on (25) of https://faculty.sites.iastate.edu/jia/files/inline-files/dual-quaternion.pdf. |
|
This internal function runs |
|
Internal method to draw a cylinder. x is a unit dual quaternion that defines the centre of the cylinder. The cylinder will span from -height_z/2 to +height_z/2. Use param_dict to define anything to be passed on to plot_surface. |
APIΒΆ
- pyplot._pyplot.plot(obj, **kwargs)ΒΆ
An aggregator for all plot functions related to dqrobotics. Currently, supports
DQ
andDQ_SerialManipulator
.Import it as follows:
import dqrobotics_extensions.pyplot as dqp
Before this can be used, please remember to initialise the plt Axes. Example:
plt.figure() ax = plt.axes(projection='3d') dqp.plot(i_) plt.show()
Plotting a unit DQ
x
(See internal functionpyplot._pyplot._plot_pose
):dqp.plot(x)
Plotting a line DQ
l_dq
(See internal functionpyplot._pyplot._plot_line
):dqp.plot(l_dq, line=True)
Plotting a plane DQ
pi_dq
(See internal functionpyplot._pyplot._plot_plane
):dqp.plot(pi_dq, plane=True)
Plotting a
DQ_SerialManipulator
calledrobot
at joint configurationsq
(See internal functionpyplot._pyplot._plot_serial_manipulator
):dqp.plot(robot, q=q)
- Parameters:
obj β The input to be plotted.
kwargs β For arguments depending on the type of plot you need, see the description above.
- Raises:
RuntimeError β If the input instance
obj
has no meaning for function, or if theobj
is not valid for the input options.
- pyplot._pyplot._plot_dq(dq: DQ, scale: float = 0.1, line=None, plane=None, sphere=None, radius=None, color='r', alpha=0.8, ax=None)ΒΆ
Implementing the pyplot valid options of https://github.com/dqrobotics/matlab/blob/master/%40DQ/plot.m the particular plotting functions did not inherit from these implementations and are an informed attempt of using DQ operators to plot the objects.
- Parameters:
dq β The input DQ.
scale β If not None, defines the size of the frame.
line β If not None, draw the input DQ as a line.
plane β If not None, draw the input DQ as a plane.
sphere β If not None, draw the input DQ as a sphere.
color β Define the color of the frame, line, or plane.
alpha β Define the alpha of the plane.
ax β Figure Axes or plt.gca() if None.
- pyplot._pyplot._plot_plane(pi_dq, length_x: float, length_y: float, color, alpha: float, ax=None)ΒΆ
Draw a plane representing the DQ pi_dq. In this plot, the normal will be represented by the local z-axis of the plane and the plane will span in its local x-y axis.
- Parameters:
pi_dq β The DQ representation of the plane.
length_x β The desired x-axis length.
length_y β The desired y-axis length.
color β Define the color of the plane.
alpha β Define the alpha of the plane.
ax β Figure Axes or plt.gca() if None.
- Raises:
RuntimeError β If argument
x
is not a plane.
- pyplot._pyplot._plot_serial_manipulator(robot: dqrobotics.robot_modeling.DQ_SerialManipulator, q: numpy.ndarray, line_color: str = 'k', line_width=3, cylinder_color: str = 'b', cylinder_alpha: float = 0.8, cylinder_radius: float = 0.02, cylinder_height: float = 0.07, ax=None)ΒΆ
Draw a serial manipulator at a given joint configuration q. Each joint transformation will be connected by a line with spec line_color and width linewidth.
- Parameters:
robot β A concrete subclass of DQ_SerialManipulator.
q β The joint configurations.
line_color β A suitable color for the line.
line_width β The width is compatible with matplotlib.
cylinder_color β A suitable color for the cylinder.
cylinder_alpha β The alpha of the cylinder.
ax β Figure Axes or plt.gca() if None.
- pyplot._pyplot._plot_pose(x: DQ, length: float = 0.1, ax=None)ΒΆ
Draw a reference frame at a given pose x.
- Parameters:
x β the pose as a unit DQ.
length β the length of each axisβ line. Has a default value.
ax β Figure Axes or plt.gca() if None.
- Raises:
RuntimeError β If argument
x
is not a unit dual quaternion.
- pyplot._pyplot._plot_line(l_dq: DQ, color: str = 'r', length: float = 10.0, ax=None)ΒΆ
Draw a line representing the DQ l_dq.
- Parameters:
l_dq β the DQ representation of the line.
color β the color.
length β the length.
ax β Figure Axes or plt.gca() if None.
- Raises:
RuntimeError β If argument
x
is not a line.
- pyplot._pyplot._plot_sphere(p: DQ, radius: float, color='b', alpha: float = 0.8, ax=None)ΒΆ
Draw a sphere of a given
radius
centered atp
, wherep
is a pure quaternion.See: https://stackoverflow.com/questions/64656951/plotting-spheres-of-radius-r.
- Parameters:
p β the DQ representing the centre of the sphere.
radius β the radius of the sphere.
color β the color of the sphere.
alpha β the transparency of the sphere.
ax β Figure Axes or plt.gca() if None.
- Raises:
RuntimeError: If
p
is not a pure quaternion.
- pyplot._pyplot.__plot_revolute_joint(x, height_z, radius, color, alpha, ax=None)ΒΆ
This internal function is used to draw cylinders, for now, for DQ_SerialManipulators. The cylinderβs height is through its z-axis, and it spans from -height_z/2 to +height_z/2.
- Parameters:
x β the pose as a DQ.
height_z β the height of the cylinder.
radius β the radius of the cylinder.
color β the color of the cylinder.
alpha β the transparency of the cylinder.
ax β Figure Axes or plt.gca() if None.
- pyplot._pyplot.__dq_adjoint(x: DQ, t: DQ)ΒΆ
This internal function currently does not seem to exist in the implementation of dqrobotics. It will be replaced when itβs available. Iβm basing this on (25) of https://faculty.sites.iastate.edu/jia/files/inline-files/dual-quaternion.pdf.
- Parameters:
x β A unit dual quaternion.
t β A pure quaternion representing the point to be transformed.
- Returns:
A pure quaternion of representing the transformed point.
- Raises:
RuntimeError β If argument
x
is not a unit dual quaternion, or ift
is not a pure quaternion.
- pyplot._pyplot.__dq_adjoint_grid(x: DQ, x_grid, y_grid, z_grid)ΒΆ
This internal function runs
__dq_adjoint
through all elements of a grid so that calculations are simplified. For instance, to move a cylinder or other surface around a plot.- Parameters:
x β A unit dual quaternion.
x_grid β A suitable x-axis grid element.
y_grid β A suitable y-axis grid element.
z_grid β A suitable z-axis grid element.
- Returns:
The transformed grids by
x
.- Raises:
RuntimeError β If argument grids have different shapes.
- pyplot._pyplot.__plot_cylinder(x, height_z: float, radius: float, color: str, alpha: float, ax=None)ΒΆ
Internal method to draw a cylinder. x is a unit dual quaternion that defines the centre of the cylinder. The cylinder will span from -height_z/2 to +height_z/2. Use param_dict to define anything to be passed on to plot_surface.
- Parameters:
x β a unit dual quaternion representing the pose of the centre of the cylinder.
height_z β the height of the cylinder.
radius β the radius of the cylinder.
color β the color of the cylinder.
alpha β the transparency of the cylinder.
ax β Figure Axes or plt.gca() if None.
- Raises:
RuntimeError β If argument
x
is not a unit dual quaternion.