Put text into non-active Axes in MATLAB
Asked Answered
C

1

7

Most MATLAB plotting commands allow you to specify which axes to act on, for instance

plot (x,y) 

plots in the current axes, but

plot(Ax, x, y) 

will plot in the axes Ax.

Similarly, you can label the x- or y- axis of a non-active axes

xlabel(Ax, 'this label goes on the x-axis of Ax whether or not Ax == gca')

But the text command doesn't appear to support this feature. Is there a way to put text into a non-active axes?

I ask because this sequence:

currentAxes = gca;
axes(Ax); %MLINT warning here
text(x,y,'this text ends up on axes Ax now');
axes(currentAxes); %MLINT warning here

will throw MLINT warnings that calling axes(axes_handle) is slow in scripted functions.

Consentaneous answered 21/9, 2010 at 13:2 Comment(0)
C
14

Use the 'Parent' property in calling the text command

text(x,y,'text','Parent', Ax)
Consentaneous answered 21/9, 2010 at 13:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.