how can i plot this kind of graph?
3 views (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Star Strider
on 21 Mar 2017
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 Comments
Star Strider
on 22 Mar 2017
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
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!