a plot of spheres with radius r

This will solve your problem

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

list_center = [(1,2,3),(-4,-5,6), (5,5,6)]
list_radius = [1,2,1]

def plt_sphere(list_center, list_radius):
  for c, r in zip(list_center, list_radius):
    ax = fig.gca(projection='3d')

    # draw sphere
    u, v = np.mgrid[0:2*np.pi:50j, 0:np.pi:50j]
    x = r*np.cos(u)*np.sin(v)
    y = r*np.sin(u)*np.sin(v)
    z = r*np.cos(v)

    ax.plot_surface(x-c[0], y-c[1], z-c[2], color=np.random.choice(['g','b']), alpha=0.5*np.random.random()+0.5)
fig = plt.figure()
plt_sphere(list_center, list_radius) 

surface plot

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top