Quantcast
Channel: Uncategorized - Matplotlib
Viewing all articles
Browse latest Browse all 40

Plot solid 3D surface on top of another one

$
0
0

Hello,
I want to plot the red and the green sphere as two solid, three-dimensional objects in this minimal working example code:

import matplotlib.pyplot as plt
import numpy as np

r = 0.05
fig = plt.figure(figsize = (12,8), constrained_layout=True)
ax = plt.axes(projection='3d')

# draw sphere 1
u, v = np.mgrid[0:2*np.pi:100j, 0:np.pi:100j]
x =  r * np.cos(u)*np.sin(v)
y = r * np.sin(u)*np.sin(v)
z =  -r + r * np.cos(v)
ax.plot_surface(x, y, z, color="r", zorder = 1, alpha = 1)

# draw sphere 2
u, v = np.mgrid[0:2*np.pi:100j, 0:np.pi:100j]
x =  r * np.cos(u)*np.sin(v)
y =  r * np.sin(u)*np.sin(v)
z =  -2*r + r * np.cos(v)
ax.plot_surface(x, y, z, color="g", zorder = 1, alpha = 1)

plt.show()

In the plot, I would like to see the boundary where the two spheres touch, but this is not what I get with the minimal working example: as I turn the image by changing the viewpoint, I see that sometimes the red sphere is on top, sometimes the green sphere is on top, see the images attached. How may I achieve this ?

I read here that the zorder optional keyword argument is usually ignored by 3d axes objects, so I don’t know how to do it.

Thanks


1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 40

Trending Articles