Marc
Marc

Reputation: 5625

Put text into non-active Axes in MATLAB

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.

Upvotes: 7

Views: 3991

Answers (1)

Marc
Marc

Reputation: 5625

Use the 'Parent' property in calling the text command

text(x,y,'text','Parent', Ax)

Upvotes: 14

Related Questions