add_text#

MapdlPlotter.add_text(text, position, font_size=12, color='white', **kwargs)#

Add text to the scene.

This method provides a backend-agnostic way to add text labels to the visualization scene. Text is positioned using 2D screen coordinates.

パラメーター:
textstr

Text string to display.

positionUnion[Tuple[float, float], str]

Position for the text. Can be:

  • 2D tuple (x, y) for screen/viewport coordinates (pixels from bottom-left)

  • String position like 'upper_left', 'upper_right', 'lower_left', 'lower_right', 'upper_edge', 'lower_edge' (backend-dependent support)

font_sizeint, default: 12

Font size for the text in points.

colorstr, default: "white"

Color of the text. Can be a color name or hex color code.

**kwargsdict

Additional backend-specific keyword arguments for advanced customization (e.g., font_family, bold, italic, shadow).

Returns:
Any

Backend-specific actor or object representing the added text. Can be used for further manipulation or removal.

戻り値の型:

Any

Examples

Add text at a screen position:

>>> from ansys.tools.visualization_interface import Plotter
>>> plotter = Plotter()
>>> plotter.add_text("Title", position=(10, 10), font_size=18, color='yellow')
>>> plotter.show()

Add text using a named position:

>>> plotter.add_text(
...     "Corner Label",
...     position='upper_right',
...     font_size=14,
...     color='red'
... )
>>> plotter.show()