I am wanting to plot all my spheres on the same graph, which should be 1 by 1 by 1. I am calling the plotting function shown below in several loops, as I want the spheres to change colours depending on some conditions. The coordinates of the centre of the spheres are described in another function in disk
. However, all the spheres that I plot do change colour but are each on separate graphs. How would I change the code below so that each time I call the function plot_disks2
, the spheres are added to the same graph. My code so far is:
def plot_disks2(disk, radius, c, ax=None):
fig = plt.figure(figsize=(12,12), dpi=300)
ax = fig.add_subplot(111, projection='3d')
u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
x = radius * np.outer(np.cos(u), np.sin(v))
y = radius * np.outer(np.sin(u), np.sin(v))
z = radius * np.outer(np.ones(np.size(u)), np.cos(v))
sphere = ax.plot_surface(x+disk[0], y+disk[1], z+disk[2], rstride=4, cstride=4, color=c, linewidth=0, alpha=0.5)
ax.add_artist(sphere)