Plot Module
Warning
This module's API is still under development and will likely change in the future.
This module contains tools to help with the plotting of geometry and other visual elements using optional plotting libraries.
Currently, the following plotting libraries are supported:
-
PyVista: A 3D visualization library that is built on top of VTK and provides tools for both interactive and static 3D rendering. The
PyvistaPlotterHelper
can wrap around a PyVistaPlotter
object to provide direct functionality for plotting someengeom
entities. -
Matplotlib: A 2D plotting library that is widely used for creating static plots. The
MatplotlibAxesHelper
class can wrap around a MatplotlibAxes
object to provide direct functionality for plotting someengeom
entities, while also forcing the aspect ratio to be 1:1 and expanding the plot to fill all available space.
GOM_CMAP = GomColorMap()
module-attribute
A color map similar to the 8 discrete colors in the GOM/Zeiss Inspect software, already instantiated and available in the module.
LabelPlace
Bases: Enum
Represents the different locations where a label can be placed between its anchor points.
Inside = 2
class-attribute
instance-attribute
The label is placed between the two anchor points.
Outside = 1
class-attribute
instance-attribute
The label is placed outside the anchor points, on the side of the second point in the measurement.
OutsideRev = 3
class-attribute
instance-attribute
The label is placed outside the two anchor points, on the side of the first point in the measurement.
PyvistaPlotterHelper
A helper class for working with PyVista. It wraps around a PyVista Plotter
object and provides direct methods
for plotting some engeom
entities.
__init__(plotter)
Initialize the helper with a PyVista Plotter
object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plotter
|
Plotter
|
The PyVista |
required |
add_curves(*curves, color='w', width=3.0, label=None, name=None)
Add one or more curves to be plotted.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
curves
|
Curve3
|
The curves to add. |
()
|
color
|
ColorLike
|
The color to use for the curve(s). |
'w'
|
width
|
float
|
The line width to use for the curve(s). |
3.0
|
label
|
str | None
|
The label to use for the curve(s) if a legend is present. |
None
|
name
|
str | None
|
The name to use for the actor in the scene. |
None
|
Returns:
Type | Description |
---|---|
vtkActor
|
The PyVista actor that was added to the plotter. |
add_mesh(mesh, **kwargs)
Add an engeom
mesh to be plotted. Additional keyword arguments will be passed directly to the PyVista
Plotter.add_mesh
method, allowing for customization of the mesh appearance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mesh
|
Mesh
|
The mesh object to add to the plotter scene |
required |
Returns:
Type | Description |
---|---|
vtkActor
|
The PyVista actor that was added to the plotter. |
coordinate_frame(iso, size=1.0)
Add a coordinate frame to the plotter. This will appear as three lines, with X in red, Y in green,
and Z in blue. The length of each line is determined by the size
parameter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
iso
|
Iso3
|
The isometry to use as the origin and orientation of the coordinate frame. |
required |
size
|
float
|
The length of each line in the coordinate frame. |
1.0
|
distance(distance, template='{value:.3f}', label_place=LabelPlace.Outside, label_offset=None, font_size=12, scale_value=1.0, font_family=None)
Add a distance entity to the plotter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
distance
|
Distance3
|
The distance entity to add. |
required |
template
|
str
|
A format string to use for the label. The |
'{value:.3f}'
|
label_place
|
LabelPlace
|
The placement of the label relative to the distance entity's anchor points. |
Outside
|
label_offset
|
float | None
|
The distance offset to use for the label. Will have different meanings depending on the |
None
|
font_size
|
int
|
The size of the text to use for the label. |
12
|
scale_value
|
float
|
A scaling factor to apply to the value before displaying it in the label. Use this to convert between different units of measurement without having to modify the actual value or the coordinate system. |
1.0
|
font_family
|
The font family to use for the label. |
None
|
label(point, text, **kwargs)
Add a text label to the plotter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point
|
PlotCoords
|
The position of the label in 3D space. |
required |
text
|
str
|
The text to display in the label. |
required |
kwargs
|
Additional keyword arguments to pass to the |
{}
|
GomColorMap
Bases: ListedColormap
A color map similar to the 8 discrete colors in the GOM/Zeiss Inspect software.
You can use this to instantiate a color map, or you can use the GOM_CMAP
object directly.
MatplotlibAxesHelper
A helper class for working with Matplotlib. It wraps around a Matplotlib Axes
object and provides direct
methods for plotting some engeom
entities. It also enforces the aspect ratio to be 1:1 and expands the
subplot to fill its available space.
Example
__init__(ax, skip_aspect=False, hide_axes=False)
Initialize the helper with a Matplotlib Axes
object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ax
|
Axes
|
The Matplotlib |
required |
skip_aspect
|
Set this to true to skip enforcing the aspect ratio to be 1:1. |
False
|
|
hide_axes
|
Set this to true to hide the axes. |
False
|
annotate_text_only(text, pos, **kwargs)
Annotate a Matplotlib Axes object with text only.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
the text to annotate |
required |
pos
|
PlotCoords
|
the position of the annotation |
required |
kwargs
|
keyword arguments to pass to the annotate function |
{}
|
Returns:
Type | Description |
---|---|
the annotation object |
arrow(start, end, arrow='-|>')
Plot an arrow on a Matplotlib Axes object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start
|
PlotCoords
|
the start point of the arrow |
required |
end
|
PlotCoords
|
the end point of the arrow |
required |
arrow
|
the style of arrow to use |
'-|>'
|
Returns:
Type | Description |
---|---|
the annotation object |
distance(distance, side_shift=0, template='{value:.3f}', fontsize=10, label_place=LabelPlace.Outside, label_offset=None, fontname=None, scale_value=1.0)
Plot a Distance2
object on a Matplotlib Axes, drawing the leader lines and adding a text label with the
distance value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
distance
|
Distance2
|
The |
required |
side_shift
|
float
|
Shift the ends of the leader lines by this amount of data units. The direction of the shift is orthogonal to the distance direction, with positive values shifting to the right. |
0
|
template
|
str
|
The format string to use for the distance label. The default is "{value:.3f}". |
'{value:.3f}'
|
fontsize
|
int
|
The font size to use for the label. |
10
|
label_place
|
LabelPlace
|
The placement of the label. |
Outside
|
label_offset
|
float | None
|
The distance offset to use for the label. Will have different meanings depending on the |
None
|
fontname
|
str | None
|
The name of the font to use for the label. |
None
|
scale_value
|
float
|
A scaling factor to apply to the value before displaying it in the label. Use this to convert between different units of measurement without having to modify the actual value or the coordinate system. |
1.0
|
plot_circle(*circle, **kwargs)
Plot a circle on a Matplotlib Axes object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
circle
|
Circle2 | Iterable[float]
|
a Circle2 object |
()
|
kwargs
|
keyword arguments to pass to the plot function |
{}
|
plot_curve(curve, **kwargs)
Plot a curve on a Matplotlib Axes object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
curve
|
Curve2
|
a Curve2 object |
required |
kwargs
|
keyword arguments to pass to the plot function |
{}
|
set_bounds(box)
Set the bounds of a Matplotlib Axes object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
box
|
Aabb2
|
an Aabb2 object |
required |