text — Add text at a position in a 2-D or 3-D plot.
text(x,y,txt) adds an annotation at a 2-D position. Include z for a 3-D position, or provide an axes handle first to select the target axes.
Syntax
h = text(x, y, label)
h = text(x, y, label, Name, Value, ...)
h = text(x, y, z, label)
h = text(x, y, z, label, Name, Value, ...)
h = text(ax, x, y, label)
h = text(ax, x, y, z, label)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
x | NumericScalar | Yes | — | X coordinate. |
y | NumericScalar | Yes | — | Y coordinate. |
label | StringScalar | Yes | — | Annotation text. |
props | Any | Variadic | — | Name/value style options. |
z | NumericScalar | Yes | — | Z coordinate. |
ax | AxesHandle | Yes | — | Target axes handle. |
Returns
| Name | Type | Description |
|---|---|---|
h | NumericScalar | Handle to the created text annotation. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:text:InvalidArgument | Coordinate, label, axes-target, or name/value text style arguments are invalid. | text: invalid argument |
RunMat:text:Internal | Internal plotting state update fails while creating annotation. | text: internal operation failed |
How text works
- Coordinates can use single, double, or any of the eight integer classes.
- The
Positionproperty retains the coordinate class, shape, and exact values. Rendering uses a separate floating-point geometry cache. - A two-element
Positionvalue is stored with a third coordinate of zero in the same numeric class. - The returned graphics handle supports
getandsetforString,Position,FontWeight,FontAngle,Interpreter,Color,FontSize, andVisible. - Typed-integer numeric axes aliases and explicit gpuArray coordinates are RunMat-mode extensions.
Examples
Label a point on a curve
plot(1:5, [2 4 3 5 4]);
h = text(4, 5, "peak");Add a 3-D annotation
plot3(1:3, 2:4, 5:7);
h = text(2, 3, 6, "sample");Use integer coordinates
h = text(int64(12), int64(-3), "checkpoint");
position = get(h, "Position")Expected output:
position = 1×3 int64
12 -3 0Using text with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how text changes the result.
Run a small text example, explain the result, then change one input and compare the output.
FAQ
Are integer positions converted to double?⌄
No. The graphics property keeps native integer storage and exact values. Only the derived coordinates sent to the renderer are converted.
Can text label several points in one call?⌄
Not yet. Each call currently accepts one scalar 2-D or 3-D position; vector coordinates and per-point label arrays remain unsupported.
Can I pass resident coordinates?⌄
Automatically resident coordinates are gathered transparently through their owning provider. Explicit gpuArray coordinates require RunMat mode because the current public compatibility target does not document an interactive GPU form for text.
Related Plotting functions
2D Charts
area · bar · errorbar · heatmap · hist · histogram · loglog · pie · plot · scatter · semilogx · semilogy · stairs · stem
Other
addpoints · ancestor · animatedline · axes · barh · caxis · cla · clf · clim · colorcube · colororder · copyobj · daspect · datacursormode · dataTipTextRow · fcontour · figure · fill · fill3 · findobj · fsurf · gobjects · groot · hgload · hgsave · hidden · histogram2 · hold · line · linkaxes · openfig · opengl · pan · parula · patch · plotmatrix · plotyy · polarhistogram · polarplot · polarscatter · print · quiver3 · ribbon · saveas · savefig · sphere · stackedplot · subtitle · suptitle · textscatter · textscatter3 · triplot · waitbar · wordcloud · xlabel · xlim · xline · xscale · xtickangle · xtickformat · xticklabels · xticks · ylabel · ylim · yline · yscale · ytickangle · ytickformat · yticklabels · yticks · zlim · zoom
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how text is executed, line by line, in Rust.
- View the source for text in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.