Duplicate subplots within loop
2 ビュー (過去 30 日間)
古いコメントを表示
Hi everyone,
i would like to duplicate plots in 2 subplots with different axis settings within a loop. What i want to do is to duplicate the plot from the first subplot and then change the axis properties. If i start with something like this:
x = linspace(-2*pi,2*pi,100);
figure
for i=1:100
y = sin(x+i);
subplot(2,1,1)
hCurve = plot(x,y,'r');
drawnow
subplot(2,1,2)
hSub2 = subplot(2,1,2);
copyobj(hCurve,hSub2);
drawnow
end
the top subplot gets refreshed every iteration, while for the bottom subplot the hold property seems to be on. Changing this property via axis handle doesn't seem to work. I suspect the copyobj function is the key, but how do i achieve the same behavior on both plots?
Thank you very much!
0 件のコメント
採用された回答
Walter Roberson
2018 年 11 月 30 日
"while for the bottom subplot the hold property seems to be on"
copyobj() adds objects to the existing destination. You generate a line in the first axes, copy it to the second axes. The next iteration, because hold is not on in the first axes, the plot() call removes the children of the first axes and adds a new line. Then you copy that new line to the second axes, but you have not remove the first line.
This is not a bug with the hold property: the hold property does not apply to situations where you copyobj(). The hold property only applies to "high level graphic routines" such as plot() but not line(), or imshow(), or image() that passes in data positionally but not image() that passes parameters as name/value pairs, or surf() (high level) but not surface() (low level).
The behaviour of "hold on" is more or less a courtesy to make using higher level graphics routines more convenient, and does not apply when low level routines such as copyobj() are used.
In other words, if you want the old content removed from subplot 212 then you will need to remove it.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Subplots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!