How can I orbit a plot3 via mouse while updating it?
1 回表示 (過去 30 日間)
古いコメントを表示
I have a plot that I want to be able to orbit with my mouse while it's updating. But every update to the plot forces the plot to go back to it's default view point. Is there a way to do what I want?
Thanks in advance!
0 件のコメント
採用された回答
Geoff Hayes
2014 年 9 月 12 日
編集済み: Geoff Hayes
2014 年 9 月 12 日
Dereck - how is your code updating the figure at each iteration? Is it re-plotting all 3D data with the addition of some new points, or are you just updating the axes with the new points?
I used the helix example from plot3 and noticed that if I plotted the data, then rotated the axes, and then plotted the data again, that the view point of the axes was restored to its original value. However, if after I rotated the axes and then called the command
hold on
for the current axes, that the subsequent call to plot the same data again, resulted in the view point of the axes remaining fixed at what I rotated it to. (For details on hold on, type doc hold - basically it retains the current graph and axes properties when adding a new graph/plot, rather than resetting/clearing the axes properties.)
So you could do the same here - call hold on just once to ensure that the axes properties (in this case View which returns the azimuth and elevation of the graph) are maintained from one call of plot3 to another. Or, just after creating the figure, you could try
set(gca,'NextPlot','add');
Which will set the current axes (its handle obtained from gca, get current axes) NextPlot property to add which will use the existing axes to draw the graph (the default is replace which resets all axes properties). See axes properties for details. This method worked well - I could rotate the figure and re-plot the graph without loss to my last view point of the axes.
その他の回答 (1 件)
Dereck
2014 年 9 月 12 日
編集済み: Dereck
2014 年 9 月 12 日
2 件のコメント
Geoff Hayes
2014 年 9 月 13 日
Strange how it slowed down over time. Was it necessary for the set(0, 'CurrentFigure', 1); inside the for loop so that it would repeat again and again?
An alternative to the deleting of the handle is to (perhaps) just replace the data at each iteration
figure(1);
% plot the first set of data outside of loop
h = plot3(X(1,:), Y(1,:), Z(1,:));
for k=2:100000
set(h,'XData',X(k,:),'YData',Y(k,:),'ZData',Z(k,:));
drawnow;
pause(0.1);
end
So we plot the first set (k==1) initially so that we can get the handle to the 3D plot graphics object. And then on each subsequent iteration of the for loop, we just replace the X,Y, and Z data.
参考
カテゴリ
Help Center および File Exchange で Specifying Target for Graphics Output についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!