how can i plot this kind of graph?

1 visualización (últimos 30 días)
Devin
Devin el 21 de Mzo. de 2017
Comentada: Star Strider el 22 de Mzo. de 2017
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!

Respuesta aceptada

Star Strider
Star Strider el 21 de Mzo. de 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 comentarios
Devin
Devin el 22 de Mzo. de 2017
Do you know how can I make the sphere color change with data? Thank you!
Star Strider
Star Strider el 22 de Mzo. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by