update figure after changing Y axis values
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Greetings.
I have some issue with updating the figure after my update of the values in Y axis. Let me explain in Figures.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1229417/image.jpeg)
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1229422/image.jpeg)
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1229427/image.jpeg)
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1229432/image.jpeg)
Please help me to retrieve the cursors.
Thank you very much.
0 commentaires
Réponses (1)
Voss
le 13 Déc 2022
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.
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!