Matplotlib’s Plot Objects#

Classes:

PlotBody(inertial_frame, zero_point, body[, ...])

A class for plotting a body in 3D using matplotlib.

PlotFrame(inertial_frame, zero_point, frame)

A class for plotting a ReferenceFrame in 3D using matplotlib.

PlotLine(inertial_frame, zero_point, line[, ...])

A class for plotting lines in 3D using matplotlib.

PlotPoint(inertial_frame, zero_point, point)

A class for plotting a Point in 3D using matplotlib.

PlotVector(inertial_frame, zero_point, vector)

A class for plotting a Vector in 3D using matplotlib.

class symmeplot.matplotlib.plot_objects.PlotBody(inertial_frame: ReferenceFrame, zero_point: Point, body: Particle | RigidBody, name: str | None = None, style: str = 'default', plot_point_properties: dict | None = None, plot_frame_properties: dict | None = None, **kwargs)#

Bases: PlotBodyMixin, MplPlotBase

A class for plotting a body in 3D using matplotlib.

Parameters:
  • inertial_frame (sympy.physics.vector.frame.ReferenceFrame) – The reference frame with respect to which the object is oriented.

  • zero_point (sympy.physics.vector.point.Point) – The absolute origin with respect to which the object is positioned.

  • body (sympy.physics.mechanics.rigidbody.RigidBody or sympy.physics.mechanics.particle.Particle) – The body that should be plotted.

  • origin (sympy.physics.vector.point.Point or sympy.physics.vector.vector.Vector, optional) – The origin of the frame with respect to the zero_point. If a sympy.physics.vector.vector.Vector is provided the origin is at the tip of the vector with respect to the zero_point. Default is zero_point.

  • style (str, optional) – Reference to what style should be used for plotting the body. The default style is 'default'. Available styles: - None: No properties of the vectors will be set. - ‘default’: Uses a special point for the center of mass and a frame with as color ‘rgb’ for xyz.

  • plot_frame_properties (dict, optional) – Dictionary of keyword arguments that should be parsed to the symemplot.matplotlib.plot_objects.PlotFrame.

  • plot_point_properties (dict, optional) – Dictionary of keyword arguments that should be parsed to the symemplot.matplotlib.plot_objects.PlotPoint representing the center of mass.

  • **kwargs (dict, optional) – Kwargs that are parsed to both internally used plot objects.

Examples

import matplotlib.pyplot as plt
import sympy as sm
import sympy.physics.mechanics as me
from symmeplot.matplotlib import PlotBody

N = me.ReferenceFrame("N")
A = me.ReferenceFrame("A")
A.orient_axis(N, N.z, 1)
N0 = me.Point("N_0")
A0 = N0.locatenew("A_0", 0.2 * N.x + 0.2 * N.y + 0.7 * N.z)
ground = me.RigidBody("ground", N0, N, 1, (N.x.outer(N.x), N0))
body = me.RigidBody("body", A0, A, 1, (A.x.outer(A.x), A0))
ground_plot = PlotBody(N, N0, ground)
body_plot = PlotBody(N, N0, body)
body_plot.attach_circle(body.masscenter, 0.3, A.x + A.y + A.z,
                        facecolor="none", edgecolor="k")
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
ground_plot.values = sm.lambdify((), ground_plot.get_expressions_to_evaluate()
                                )()
body_plot.values = sm.lambdify((), body_plot.get_expressions_to_evaluate())()
ground_plot.update()  # Updates the artist(s) to the new values
body_plot.update()  # Updates the artist(s) to the new values
ground_plot.plot(ax)
body_plot.plot(ax)
../../_images/plot_objects_0_0.png

Methods:

add_artist(artist, exprs)

Add an artist to the plot object.

attach_circle(center, radius, normal, **kwargs)

Attaches a circle to a point to represent the body.

contains(event)

Boolean whether one of the artists contains the event.

get_expressions_to_evaluate()

Return a tuple of the necessary expressions for plotting.

get_sympy_object_exprs()

Return the expressions used in plotting the sympy object.

plot([ax])

Plot the associated plot objects.

update()

Update the objects on the scene, based on the currect values.

Attributes:

annot_coords

Coordinate where the annotation text is displayed.

artists

Artists used to plot the object.

body

The sympy body, which is being plotted.

children

Child objects in the plot hierarchy.

inertial_frame

The reference frame with respect to which the object is oriented.

name

Name of the plot object.

plot_frame

PlotFrame used for plotting the reference frame of the body.

plot_masscenter

PlotPoint used for plotting the center of mass of the body.

sympy_object

The absolute origin with respect to which the object is positioned.

values

List of evaluated values for the object's variables.

visible

If the object is be visible in the plot.

zero_point

The absolute origin with respect to which the object is positioned.

add_artist(artist: ArtistBase, exprs: Expr | tuple[Expr, ...])#

Add an artist to the plot object.

Parameters:
  • artist (ArtistBase) – The artist to be added.

  • exprs (expression or tuple of expressions) – Args used to update the artist in the form of expressions.

property annot_coords#

Coordinate where the annotation text is displayed.

property artists: tuple[ArtistBase, ...]#

Artists used to plot the object.

attach_circle(center, radius, normal, **kwargs)#

Attaches a circle to a point to represent the body.

Parameters:
Returns:

Circle artist.

Return type:

symmeplot.matplotlib.plot_artists.Circle3D

property body: Particle | RigidBody#

The sympy body, which is being plotted.

property children: tuple[PlotBase, ...]#

Child objects in the plot hierarchy.

contains(event)#

Boolean whether one of the artists contains the event.

get_expressions_to_evaluate() tuple#

Return a tuple of the necessary expressions for plotting.

get_sympy_object_exprs() tuple[Any, ...]#

Return the expressions used in plotting the sympy object.

property inertial_frame: sympy.physics.vector.frame.ReferenceFrame#

The reference frame with respect to which the object is oriented.

property name: str#

Name of the plot object. Default is the name of the object being plotted.

plot(ax=None)#

Plot the associated plot objects.

Explanation

Add the objects artists to the matplotlib axes. Note that the object should be evaluated before plotting.

Parameters:

ax (matplotlib.axes._subplots.Axes3DSubplot, optional) – Axes on which the artist should be added. The default is the active axes.

property plot_frame: PlotBase | None#

PlotFrame used for plotting the reference frame of the body.

property plot_masscenter: PlotBase#

PlotPoint used for plotting the center of mass of the body.

property sympy_object: Any#

The absolute origin with respect to which the object is positioned.

update() None#

Update the objects on the scene, based on the currect values.

property values: tuple#

List of evaluated values for the object’s variables.

property visible: bool#

If the object is be visible in the plot.

property zero_point: sympy.physics.vector.point.Point#

The absolute origin with respect to which the object is positioned.

class symmeplot.matplotlib.plot_objects.PlotFrame(inertial_frame: ReferenceFrame, zero_point: Point, frame: ReferenceFrame, origin: Point | Vector | None = None, name: str | None = None, scale: float = 0.1, style: str = 'default', **kwargs)#

Bases: PlotFrameMixin, MplPlotBase

A class for plotting a ReferenceFrame in 3D using matplotlib.

Parameters:
  • inertial_frame (sympy.physics.vector.frame.ReferenceFrame) – The reference frame with respect to which the object is oriented.

  • zero_point (sympy.physics.vector.point.Point) – The absolute origin with respect to which the object is positioned.

  • frame (sympy.physics.vector.frame.ReferenceFrame) – The reference frame that should be plotted.

  • origin (sympy.physics.vector.point.Point or sympy.physics.vector.vector.Vector, optional) – The origin of the frame with respect to the zero_point. If a sympy.physics.vector.vector.Vector is provided the origin is at the tip of the vector with respect to the zero_point. Default is zero_point.

  • style (str, optional) – Reference to what style should be used for plotting the frame. The default style is 'default'. Available styles: - None: No properties of the vectors will be set. - ‘default’: Nice default frame with as color ‘rgb’ for xyz.

  • scale (float, optional) – Length of the vectors of the reference frame.

  • **kwargs (dict, optional) – Kwargs that are parsed to symmeplot.matplotlib.plot_objects.PlotVector`s, which possibly parses them to :class:`matplotlib.patches.FancyArrow, so color='r' will make all vectors of the reference frame red.

Examples

import matplotlib.pyplot as plt
import sympy as sm
import sympy.physics.mechanics as me
from symmeplot.matplotlib import PlotFrame

N = me.ReferenceFrame("N")
A = me.ReferenceFrame("A")
A.orient_axis(N, N.z, 1)
N0 = me.Point("N_0")
A0 = N0.locatenew("A_0", 0.2 * N.x + 0.2 * N.y + 0.7 * N.z)
N_plot = PlotFrame(N, N0, N, scale=0.5)
A_plot = PlotFrame(N, N0, A, A0, scale=0.5, ls="--")
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
N_plot.values = sm.lambdify((), N_plot.get_expressions_to_evaluate())()
A_plot.values = sm.lambdify((), A_plot.get_expressions_to_evaluate())()
N_plot.update()  # Updates the artist(s) to the new values
A_plot.update()  # Updates the artist(s) to the new values
N_plot.plot(ax)
A_plot.plot(ax)
../../_images/plot_objects_1_0.png

Methods:

add_artist(artist, exprs)

Add an artist to the plot object.

contains(event)

Boolean whether one of the artists contains the event.

get_expressions_to_evaluate()

Return a tuple of the necessary expressions for plotting.

get_sympy_object_exprs()

Return the expressions used in plotting the sympy object.

plot([ax])

Plot the associated plot objects.

update()

Update the objects on the scene, based on the currect values.

Attributes:

annot_coords

Coordinate where the annotation text is displayed.

artists

Artists used to plot the object.

children

Child objects in the plot hierarchy.

frame

The sympy ReferenceFrame, which is being plotted.

inertial_frame

The reference frame with respect to which the object is oriented.

name

Name of the plot object.

origin

The origin of the object with respect to the zero_point.

sympy_object

The absolute origin with respect to which the object is positioned.

values

List of evaluated values for the object's variables.

vectors

The PlotVectors used to plot the reference frame.

visible

If the object is be visible in the plot.

x

PlotVector used for the unit vector in the x direction.

y

PlotVector used for the unit vector in the y direction.

z

PlotVector used for the unit vector in the z direction.

zero_point

The absolute origin with respect to which the object is positioned.

add_artist(artist: ArtistBase, exprs: Expr | tuple[Expr, ...])#

Add an artist to the plot object.

Parameters:
  • artist (ArtistBase) – The artist to be added.

  • exprs (expression or tuple of expressions) – Args used to update the artist in the form of expressions.

property annot_coords#

Coordinate where the annotation text is displayed.

property artists: tuple[ArtistBase, ...]#

Artists used to plot the object.

property children: tuple[PlotBase, ...]#

Child objects in the plot hierarchy.

contains(event)#

Boolean whether one of the artists contains the event.

property frame: sympy.physics.vector.frame.ReferenceFrame#

The sympy ReferenceFrame, which is being plotted.

get_expressions_to_evaluate() tuple#

Return a tuple of the necessary expressions for plotting.

get_sympy_object_exprs() tuple[Any, ...]#

Return the expressions used in plotting the sympy object.

property inertial_frame: sympy.physics.vector.frame.ReferenceFrame#

The reference frame with respect to which the object is oriented.

property name: str#

Name of the plot object. Default is the name of the object being plotted.

property origin: sympy.physics.vector.point.Point#

The origin of the object with respect to the zero_point.

plot(ax=None)#

Plot the associated plot objects.

Explanation

Add the objects artists to the matplotlib axes. Note that the object should be evaluated before plotting.

Parameters:

ax (matplotlib.axes._subplots.Axes3DSubplot, optional) – Axes on which the artist should be added. The default is the active axes.

property sympy_object: Any#

The absolute origin with respect to which the object is positioned.

update() None#

Update the objects on the scene, based on the currect values.

property values: tuple#

List of evaluated values for the object’s variables.

property vectors: tuple[PlotBase, PlotBase, PlotBase]#

The PlotVectors used to plot the reference frame.

property visible: bool#

If the object is be visible in the plot.

property x: PlotBase#

PlotVector used for the unit vector in the x direction.

property y: PlotBase#

PlotVector used for the unit vector in the y direction.

property z: PlotBase#

PlotVector used for the unit vector in the z direction.

property zero_point: sympy.physics.vector.point.Point#

The absolute origin with respect to which the object is positioned.

class symmeplot.matplotlib.plot_objects.PlotLine(inertial_frame: sympy.physics.vector.frame.ReferenceFrame, zero_point: sympy.physics.vector.point.Point, line: Iterable[sympy.physics.vector.point.Point], name: str | None = None, **kwargs)#

Bases: PlotLineMixin, MplPlotBase

A class for plotting lines in 3D using matplotlib.

Parameters:

Examples

import matplotlib.pyplot as plt
import sympy as sm
import sympy.physics.mechanics as me
from symmeplot.matplotlib import PlotLine

l1, l2, l3 = sm.symbols("l:3")
N, O = me.ReferenceFrame("N"), me.Point("O")
P1 = O.locatenew("P1", (l1 * N.x + l2 * N.y + l3 * N.z))
P2 = P1.locatenew("P2", -0.3 * N.x)
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
line_plot = PlotLine(N, O, [O, P1, P2], color="k")
f = sm.lambdify((l1, l2, l3), line_plot.get_expressions_to_evaluate())
line_plot.values = f(0, 0, 0)
line_plot.update()  # Updates the artist(s) to the new values
line_plot.plot()  # Plot the point
line_plot.values = f(0.2, 0.6, 0.3)
line_plot.update()  # The point will now be on its new position
../../_images/plot_objects_2_0.png

Methods:

add_artist(artist, exprs)

Add an artist to the plot object.

contains(event)

Boolean whether one of the artists contains the event.

get_expressions_to_evaluate()

Return a tuple of the necessary expressions for plotting.

get_sympy_object_exprs()

Arguments of the sympy object artist in expression form.

plot([ax])

Plot the associated plot objects.

update()

Update the objects on the scene, based on the currect values.

Attributes:

annot_coords

Coordinate where the annotation text is displayed.

artists

Artists used to plot the object.

children

Child objects in the plot hierarchy.

inertial_frame

The reference frame with respect to which the object is oriented.

line

The points that spawn the line.

line_coords

Coordinate values of the plotted line.

name

Name of the plot object.

sympy_object

The absolute origin with respect to which the object is positioned.

values

List of evaluated values for the object's variables.

visible

If the object is be visible in the plot.

zero_point

The absolute origin with respect to which the object is positioned.

add_artist(artist: ArtistBase, exprs: Expr | tuple[Expr, ...])#

Add an artist to the plot object.

Parameters:
  • artist (ArtistBase) – The artist to be added.

  • exprs (expression or tuple of expressions) – Args used to update the artist in the form of expressions.

property annot_coords#

Coordinate where the annotation text is displayed.

property artists: tuple[ArtistBase, ...]#

Artists used to plot the object.

property children: tuple[PlotBase, ...]#

Child objects in the plot hierarchy.

contains(event)#

Boolean whether one of the artists contains the event.

get_expressions_to_evaluate() tuple#

Return a tuple of the necessary expressions for plotting.

get_sympy_object_exprs() tuple[tuple[Expr, ...], ...]#

Arguments of the sympy object artist in expression form.

Notes

The form of the expression is ((x0, x1, ...), (y0, y1, ...), (z0, z1, ...)).

property inertial_frame: sympy.physics.vector.frame.ReferenceFrame#

The reference frame with respect to which the object is oriented.

property line: tuple[sympy.physics.vector.point.Point, ...]#

The points that spawn the line.

property line_coords: ndarray[Any, dtype[float64]]#

Coordinate values of the plotted line.

property name: str#

Name of the plot object. Default is the name of the object being plotted.

plot(ax=None)#

Plot the associated plot objects.

Explanation

Add the objects artists to the matplotlib axes. Note that the object should be evaluated before plotting.

Parameters:

ax (matplotlib.axes._subplots.Axes3DSubplot, optional) – Axes on which the artist should be added. The default is the active axes.

property sympy_object: Any#

The absolute origin with respect to which the object is positioned.

update() None#

Update the objects on the scene, based on the currect values.

property values: tuple#

List of evaluated values for the object’s variables.

property visible: bool#

If the object is be visible in the plot.

property zero_point: sympy.physics.vector.point.Point#

The absolute origin with respect to which the object is positioned.

class symmeplot.matplotlib.plot_objects.PlotPoint(inertial_frame: sympy.physics.vector.frame.ReferenceFrame, zero_point: sympy.physics.vector.point.Point, point: sympy.physics.vector.point.Point, name: str | None = None, style: str = 'default', **kwargs)#

Bases: PlotPointMixin, MplPlotBase

A class for plotting a Point in 3D using matplotlib.

Parameters:

Examples

import matplotlib.pyplot as plt
import sympy as sm
import sympy.physics.mechanics as me
from symmeplot.matplotlib import PlotPoint

l1, l2, l3 = sm.symbols("l:3")
N, O = me.ReferenceFrame("N"), me.Point("O")
P1 = O.locatenew("P1", (l1 * N.x + l2 * N.y + l3 * N.z))
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
plot_point = PlotPoint(N, O, P1, color="k")
f = sm.lambdify((l1, l2, l3), plot_point.get_expressions_to_evaluate())
plot_point.values = f(0, 0, 0)
plot_point.update()  # Updates the artist(s) to the new values
plot_point.plot()  # Plot the point
plot_point.values = f(0.2, 0.6, 0.3)
plot_point.update()  # The point will now be on its new position
../../_images/plot_objects_3_0.png

Methods:

add_artist(artist, exprs)

Add an artist to the plot object.

contains(event)

Boolean whether one of the artists contains the event.

get_expressions_to_evaluate()

Return a tuple of the necessary expressions for plotting.

get_sympy_object_exprs()

Get coordinate of the point as expressions.

plot([ax])

Plot the associated plot objects.

update()

Update the objects on the scene, based on the currect values.

Attributes:

annot_coords

Coordinate where the annotation text is displayed.

artists

Artists used to plot the object.

children

Child objects in the plot hierarchy.

inertial_frame

The reference frame with respect to which the object is oriented.

name

Name of the plot object.

point

The sympy Point, which is being plotted.

point_coords

Coordinate values of the plotted point.

sympy_object

The absolute origin with respect to which the object is positioned.

values

List of evaluated values for the object's variables.

visible

If the object is be visible in the plot.

zero_point

The absolute origin with respect to which the object is positioned.

add_artist(artist: ArtistBase, exprs: Expr | tuple[Expr, ...])#

Add an artist to the plot object.

Parameters:
  • artist (ArtistBase) – The artist to be added.

  • exprs (expression or tuple of expressions) – Args used to update the artist in the form of expressions.

property annot_coords#

Coordinate where the annotation text is displayed.

property artists: tuple[ArtistBase, ...]#

Artists used to plot the object.

property children: tuple[PlotBase, ...]#

Child objects in the plot hierarchy.

contains(event)#

Boolean whether one of the artists contains the event.

get_expressions_to_evaluate() tuple#

Return a tuple of the necessary expressions for plotting.

get_sympy_object_exprs() tuple[Expr, Expr, Expr]#

Get coordinate of the point as expressions.

property inertial_frame: sympy.physics.vector.frame.ReferenceFrame#

The reference frame with respect to which the object is oriented.

property name: str#

Name of the plot object. Default is the name of the object being plotted.

plot(ax=None)#

Plot the associated plot objects.

Explanation

Add the objects artists to the matplotlib axes. Note that the object should be evaluated before plotting.

Parameters:

ax (matplotlib.axes._subplots.Axes3DSubplot, optional) – Axes on which the artist should be added. The default is the active axes.

property point: sympy.physics.vector.point.Point#

The sympy Point, which is being plotted.

property point_coords: ndarray[Any, dtype[float64]]#

Coordinate values of the plotted point.

property sympy_object: Any#

The absolute origin with respect to which the object is positioned.

update() None#

Update the objects on the scene, based on the currect values.

property values: tuple#

List of evaluated values for the object’s variables.

property visible: bool#

If the object is be visible in the plot.

property zero_point: sympy.physics.vector.point.Point#

The absolute origin with respect to which the object is positioned.

class symmeplot.matplotlib.plot_objects.PlotVector(inertial_frame: ReferenceFrame, zero_point: Point, vector: Vector, origin: Point | Vector | None = None, name: str | None = None, style: str = 'default', **kwargs)#

Bases: PlotVectorMixin, MplPlotBase

A class for plotting a Vector in 3D using matplotlib.

Parameters:

Examples

import matplotlib.pyplot as plt
import sympy as sm
import sympy.physics.mechanics as me
from symmeplot.matplotlib import PlotVector

N = me.ReferenceFrame("N")
O = me.Point("O")
O_v = O.locatenew("O_v", 0.2 * N.x + 0.2 * N.y + 0.7 * N.z)
v = 0.4 * N.x + 0.4 * N.y - 0.6 * N.z
v_plot = PlotVector(N, O, v, O_v, color="r", ls="--")
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
v_plot.values = sm.lambdify((), v_plot.get_expressions_to_evaluate())()
v_plot.update()  # Updates the artist(s) to the new values
v_plot.plot(ax)
../../_images/plot_objects_4_0.png

Methods:

add_artist(artist, exprs)

Add an artist to the plot object.

contains(event)

Boolean whether one of the artists contains the event.

get_expressions_to_evaluate()

Return a tuple of the necessary expressions for plotting.

get_sympy_object_exprs()

Arguments of the sympy object artist in expression form.

plot([ax])

Plot the associated plot objects.

update()

Update the objects on the scene, based on the currect values.

Attributes:

annot_coords

Coordinate where the annotation text is displayed.

artists

Artists used to plot the object.

children

Child objects in the plot hierarchy.

inertial_frame

The reference frame with respect to which the object is oriented.

name

Name of the plot object.

origin

The origin of the object with respect to the zero_point.

origin_coords

Coordinate values of the origin of the plotted vector.

sympy_object

The absolute origin with respect to which the object is positioned.

values

List of evaluated values for the object's variables.

vector

The sympy Vector, which is being plotted.

vector_values

Values of the plotted vector.

visible

If the object is be visible in the plot.

zero_point

The absolute origin with respect to which the object is positioned.

add_artist(artist: ArtistBase, exprs: Expr | tuple[Expr, ...])#

Add an artist to the plot object.

Parameters:
  • artist (ArtistBase) – The artist to be added.

  • exprs (expression or tuple of expressions) – Args used to update the artist in the form of expressions.

property annot_coords#

Coordinate where the annotation text is displayed.

property artists: tuple[ArtistBase, ...]#

Artists used to plot the object.

property children: tuple[PlotBase, ...]#

Child objects in the plot hierarchy.

contains(event)#

Boolean whether one of the artists contains the event.

get_expressions_to_evaluate() tuple#

Return a tuple of the necessary expressions for plotting.

get_sympy_object_exprs() tuple[tuple[Expr, ...], tuple[Expr, ...]]#

Arguments of the sympy object artist in expression form.

property inertial_frame: sympy.physics.vector.frame.ReferenceFrame#

The reference frame with respect to which the object is oriented.

property name: str#

Name of the plot object. Default is the name of the object being plotted.

property origin: sympy.physics.vector.point.Point#

The origin of the object with respect to the zero_point.

property origin_coords: ndarray[Any, dtype[float64]]#

Coordinate values of the origin of the plotted vector.

plot(ax=None)#

Plot the associated plot objects.

Explanation

Add the objects artists to the matplotlib axes. Note that the object should be evaluated before plotting.

Parameters:

ax (matplotlib.axes._subplots.Axes3DSubplot, optional) – Axes on which the artist should be added. The default is the active axes.

property sympy_object: Any#

The absolute origin with respect to which the object is positioned.

update() None#

Update the objects on the scene, based on the currect values.

property values: tuple#

List of evaluated values for the object’s variables.

property vector: sympy.physics.vector.vector.Vector#

The sympy Vector, which is being plotted.

property vector_values: ndarray[Any, dtype[float64]]#

Values of the plotted vector.

property visible: bool#

If the object is be visible in the plot.

property zero_point: sympy.physics.vector.point.Point#

The absolute origin with respect to which the object is positioned.