MATLAB Answers

0

Text Box location Issue

Hans123 님이 질문을 제출함. 18 Apr 2019
최근 활동 Star Strider 님이 댓글을 추가함. 18 Apr 2019
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
matlab.png

  댓글 수: 0

로그인 to comment.

제품

답변 수: 1

Star Strider 님의 답변 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

Thank you for the reply, but I don't think your answer really applies to my situation (or I did not understand what you stated).
My axes should change to zoom out and show the bigger picture (shown in the below picture).
Right now my text is in handles and they update with the data in the loop
matlab2.png
% hp = plot(dist, model, 'r-', 'Linewidth', 1.5);
txt1 = ['V_{preamp} = ' num2str(aaa) ' / (Tool-Substrate Gap + (' num2str(bbb) '))'];
ht = text(400, 650, txt1, 'FontSize', 9);
txt2 = ['Current V_{preamp} value = ' num2str(Mean(k)) '| Current Z-piezo distance = (' num2str(Mean_step(k)) '))'];
ht2 = text(400, 600, txt2, 'FontSize', 9);
txt3 =['Current Z-piezo distance = ' num2str(Mean_step(k)) ''];
ht3 = text(400, 550, txt3, 'FontSize', 9);
% hh=animatedline('Marker','o','MarkerSize', 3,'MarkerFaceColor',[0.2 0.2 0.2]);
% h = plot(nan, nan, 'yo', 'MarkerSize', 5, 'MarkerFaceColor', 'g','MarkerEdgeColor','g'); %yellow, filled, large
for k = 2:length(Mean)
% y1=Mean(k);
% % x1=Mean_step(k);
% y2=Mean(k);
% x2=Mean(k);
% ...
% model = aaa./(dist + bbb);
% hp.YData = model;
txt1 = ['V= ' num2str(aaa) ' / ( Gap + (' num2str(bbb) '))'];
ht.String = txt1;
% addpoints(hh, Mean_step(k), Mean(k))
txt2 = ['Current value = ' num2str(Mean(k)) ' V'];
ht2.String = txt2;
txt3 =['Current piezo distance = ' num2str(Mean_step(k)) ' \mum'];
ht3.String = txt3;
% set(h, 'XData', Mean_step(k), 'YData', Mean(k));
drawnow()
% Plot in a loop and grab frames
% frame = getframe(gcf); %get frame
% writeVideo(myVideo, frame);
end
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.

로그인 to comment.



Translated by