how can i plot this kind of graph?

조회 수: 1 (최근 30일)
Devin
Devin 2017년 3월 21일
댓글: Star Strider 2017년 3월 22일
Hi everyone, I need to plot this kind of graph in my paper. Can anyone give me some hints how to plot it by matlab? Thank you very much!

채택된 답변

Star Strider
Star Strider 2017년 3월 21일
This will get you started:
N = 10;
[X,Y,Z] = sphere(N-1);
Xr = randi(20, 10, 1);
Yr = randi(20, 10, 1);
Zr = randi(20, 10, 1);
for k1 = 1:N
Xv{k1} = X + Xr(k1);
Yv{k1} = Y + Yr(k1);
Zv{k1} = Z + Zr(k1);
end
figure(1)
surf(Xv{1}, Yv{1}, Zv{1})
hold on
for k1 = 2:N
surf(Xv{k1}, Yv{k1}, Zv{k1})
end
hold off
set(gca, 'Box','on', 'BoxStyle','full', 'XTick',[], 'YTick',[], 'ZTick',[])
grid off
axis equal
This will produce a plot similar to ‘B’. You will have to experiment with the patch function to get the box colors in ‘A’.
See the documentation for the relevant functions for details on how to use them.
  댓글 수: 4
Devin
Devin 2017년 3월 22일
Do you know how can I make the sphere color change with data? Thank you!
Star Strider
Star Strider 2017년 3월 22일
I thought they did in the plot in my code. There weren’t many spheres, so the color change wasn’t as obvious as it would be with more.
It’s a bit more obvious in this slightly revised code:
Nf = 10; % Sphere Faces
[X,Y,Z] = sphere(Nf-1);
Ns = 250; % Number Of Spheres
Xr = randi(20, Ns, 1);
Yr = randi(20, Ns, 1);
Zr = randi(20, Ns, 1);
for k1 = 1:Ns
Xv{k1} = X + Xr(k1);
Yv{k1} = Y + Yr(k1);
Zv{k1} = Z + Zr(k1);
end
figure(1)
surf(Xv{1}, Yv{1}, Zv{1})
colormap(jet)
hold on
for k1 = 2:Ns
surf(Xv{k1}, Yv{k1}, Zv{k1})
end
hold off
set(gca, 'Box','on', 'BoxStyle','full', 'XTick',[], 'YTick',[], 'ZTick',[], 'LineWidth',2)
grid off
axis equal

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by