update figure after changing Y axis values

1 回表示 (過去 30 日間)
Dimani4
Dimani4 2022 年 12 月 13 日
コメント済み: Dimani4 2022 年 12 月 14 日
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.

回答 (1 件)

Voss
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.
  1 件のコメント
Dimani4
Dimani4 2022 年 12 月 14 日
Thank you very much for your answer.
Actually what I did is before updating the figure I read the values of the cursors like:
val=dualcursor_D_v2a;
And then after I update the figure I just call the cursors again in their old places as it was before updating.
dualcursor_D_v2a([val(1) val(3)],[],'r');

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by