Text Box location Issue
7 views (last 30 days)
Show older comments
Hi,
I have an animated plot that changes axis limits as it updates, the text I have (which is docked to a certain location of the graph) moves as the axis updates too. How can I anchor it on one section so it doesn't get compressed and unreadable like the image I pasted at the bottom.
**I cannot fix the axis limits using xlim and ylim, because it defeats the purpose of the information I need to collect
In a nutshell, I am trying to fix the text onto the graph just like how the legend box is anchored
0 Comments
Accepted Answer
Star Strider
on 18 Apr 2019
I would define the axis limits just after the plot call with an axis call. The axis limits will not then change in each iteration. This may have its drawbacks if you cannot define what the ‘correct’ axis limits will be at the outset of your code.
Example —
[Xs,Ys,Zs] = sphere;
figure
for k1 = 1:0.03:3.2
Xp = Xs + cos(k1*2*pi);
Yp = Ys + sin(k1*2*pi);
surf(Xp, Yp, Zs)
axis equal
axis([-3 3 -3 3 -3 3])
text(-2.1, -1.8, 'Revolving Sphere')
view(0,90)
grid on
refreshdata
drawnow update
end
hold off
Experiment to get the result you want.
2 Comments
Star Strider
on 18 Apr 2019
My pleasure.
To use my idea, you would need to specify in an axis call what the maximum limits of your axes are, so they would not change as your data changed. Then, you could specify your text positions that would not change relative to your fixed axis limits.
If you cannot fix your axis limits iimmediately after your plot call in every iteration, then my code is not appropriate to your application.
Alternatively, you could position your text objects relative to your axis limits, setting them dynamically relative to the limits.
For example:
text(min(xlim)+0.1*diff(xlim), max(ylim)-0.2*diff(ylim), 'Your Text Here')
This is partially tested. It works, although I did not test it with dynamic axis limit resizing. You would put it just after your plot call.
Experiment to get the result you want.
More Answers (0)
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!