Question

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.

Was it helpful?

Solution

Use the 'Parent' property in calling the text command

text(x,y,'text','Parent', Ax)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top