update figure after changing Y axis values
1 次查看(过去 30 天)
显示 更早的评论
Greetings.
I have some issue with updating the figure after my update of the values in Y axis. Let me explain in Figures.
Actually my purpose is remove the slope.
axes_objects=hObject.Parent.Children(strcmp(get(hObject.Parent.Children,'Type'),'axes'));
X=axes_objects(i).Children(end).XData;
Y=axes_objects(i).Children(end).YData;
polyf=polyfit(X,Y,1);
polyv=polyval(polyf,X);
correct_y=Y-polyv;
set(axes_objects(i).Children(end),'YData',correct_y);
minmax_detr=[min(correct_y)-abs(0.1*min(correct_y)) max(correct_y)+0.1*max(correct_y)];
set(axes_objects(i).Children(end).Parent,'YLim',minmax_detr)
So in brief. I find my profile picture, get X,Y and then find the linear slope and then just do difference between the previous Y and the slope. Then I set YData with the new Y and set the limits in the new pictures.
But after I update the new graph with the new line the cursors in the new updated pictures are disappeared. Take a look.
But they are still in the Children of the figure: 1,2,3,4 this is what still in the picture but the rest I don't see.
I thought maybe ifI remove the background they will appear
set(axes_objects(i).Children(end).Parent,'Color', 'None');
But no. I see only grey background and no traces of cursors.
Please help me to retrieve the cursors.
Thank you very much.
0 个评论
回答(1 个)
Voss
2022-12-13
When you set the axes YLim
set(axes_objects(i).Children(end).Parent,'YLim',minmax_detr)
the cursor lines don't update automatically so they're now off-scale. Just set their YData to the same YLim:
set(axes_objects(i).Children([5 6]),'YData',minmax_detr)
and update the cursor texts Position as well:
text_y_val = mean(minmax_detr); % pick some y-location(s) you like
for idx = [7 8]
text_pos = axes_objects(i).Children(idx).Position;
text_pos(2) = text_y_val;
axes_objects(i).Children(idx).Position = text_pos;
end
Of course, this is assuming that axes_objects(i).Children is as it is shown in your screen shot, so that elements 5, 6, 7, 8 are always the cursor lines and texts. That may be a bad assumption if you add or remove anything from the axes later on, so you really should store handles to graphics objects as variables in their own right and not assume some particular child ordering.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!