0

I have a dataset with 4 columns (x, y, z, size), and want to produce a scatter plot of spheres in 3D like the following Fig.1. What I have been able to produce so far is shown in Fig.2. The spheres are not smooth and the color is not shiny like what I want.

Fig.1 (what I want)

Fig.2 (what I have produced so far

Any ideas on how to make the spheres look smooth and colored shiny? Thank you.

The code I am using is given below:

def drawSphere(xCenter, yCenter, zCenter, r):
    #draw sphere
    u, v = np.mgrid[0:2*np.pi:20j, 0:np.pi:10j]
    x=np.cos(u)*np.sin(v)
    y=np.sin(u)*np.sin(v)
    z=np.cos(v)
    # shift and scale sphere
    x = r*x + xCenter
    y = r*y + yCenter
    z = r*z + zCenter
    return (x,y,z)

# draw a sphere for each data point
amplifier = 2500 # to magnify the spheres
for i, (xi,yi,zi,ri) in enumerate(zip(location['x'],location['y'],location['z'],location['amp']/amplifier)):
    (xs,ys,zs) = drawSphere(xi,yi,zi,ri)
    ax.plot_surface(xs, ys, zs, color = cmap(norm(location['amp'][i])), edgecolor='none', alpha=1)
Suren
  • 1
  • 1
    Matplotlib only has limited 3D support. You could try Mayavi instead. – JohanC Apr 15 '22 at 14:34
  • The idea is to increase the number of discretization points for the sphere and then setup a light source. Doing so, will slow down thing quite significantly because Matplotlib doesn't have a great 3D support. You can try a different library, for example Plotly or K3D jupyter. – Davide_sd Apr 15 '22 at 14:40

0 Answers0