Using "hold all" and "hold on" for a 3D scatterplot

조회 수: 35 (최근 30일)
Yasmeen
Yasmeen 2014년 1월 14일
댓글: Walter Roberson 2014년 1월 15일
I am making a large number of figures proceeded by a for loop. Every iteration of the for loop adds a plot layer on top of each figure.
Using "hold all" and calling the figure axes works for all of these scatterplots except for one, which is a 3D scatterplot (made using scatter3). This figure displays only the information from the last iteration.
Is there a reason why scatter3 wouldn't have the same hold properties as scatter, and if so, how can I make the plots hold? Thanks!

채택된 답변

Yasmeen
Yasmeen 2014년 1월 15일
Mystery solved! There was a stray "hold off" earlier in the code that didn't affect any figures except for this one. Why it didn't affect the other figures is equally mysterious to me, but I'm glad it works now!
  댓글 수: 1
Walter Roberson
Walter Roberson 2014년 1월 15일
"hold off" without an axes specification only applies to the "current axes" of the time.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2014년 1월 14일
If you are using
scatter2(...)
hold on
scatter3(...)
then the 2D view from the scatter2() is held, so the scatter3() that goes on top of it appears to give a 2D result. If you rotate the view after the scatter3() then you can see the points in their proper respective positions.
scatter(rand(1,10),rand(1,10))
hold on
scatter3(rand(1,10),rand(1,10),rand(1,10))
Now click on the rotate tool in the toolbar and rotate out of plane; the blue 2D points will show up all at z = 0 as expected.
  댓글 수: 2
Yasmeen
Yasmeen 2014년 1월 14일
편집: Yasmeen 2014년 1월 14일
Thanks for your response, Walter! Unfortunately, that's not quite what I meant. Here is the code for what I mean:
%%The code
f1 = figure('Name',strcat('Projections')); hold all; a1 = gca;
f2 = figure('Name',strcat(Object,'Track')); hold all; a2 = gca;
% f3 through f13 have the same format as f1 and f2
f14 = figure('Name',strcat('x vs t vs c')); hold all; a14 = gca;
% Start for loop
for i = 1:length(ind)
% plot figure 1
scatter(a1, c, v_x) % this plots the correct number of layers
% plot figure 2
scatter(a2, x, y) % this plots the correct number of layers
% plot figures 3 through 13, in same format as figures 1 and 2
% plot figure 14
scatter3(a14 , x_non, t_non, c) % only the last plot shows up
end
% label axes
xlabel(a1, 'time'); ylabel(a1, 'projection on x'); % fig 1
xlabel(a2,'x'); ylabel(a2,'y'); % fig 2
% label figures 3 through 13 in the same format as figures 1 and 2
xlabel(a14,'x_non'); ylabel(a14,'t_non'); zlabel(a14,'c'); %fig 14
I end up with 13 2D scatter plots that have several layers each, and one 3D scatter plot that only has the last layer. Does that clear things up? Thanks!
Walter Roberson
Walter Roberson 2014년 1월 15일
The obvious supposition would be that you do not have "hold on" applied on axis a14.
hold(a14, 'on')

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by