how can i plot this kind of graph?

1 次查看(过去 30 天)
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