Text Box location Issue
9 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Star Strider
2019-4-18
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 个评论
Star Strider
2019-4-18
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Performance 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!