I was using plot_surface
to create a conical structure with up and down parts in 3D, see code below. With viewing angle azim=90.
the bottom cone is lighter on the left and darker on the right. One would expect the same for the top cone if the "light source" is coming from the left side. However, the upper cone has opposite shading and remains so for other viewing angles I choose.
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure(figsize=(3,4));
ax = fig.add_subplot(111,projection='3d')
theta = np.linspace(0,2*np.pi,360)
r = np.linspace(0,1,100)
T, R = np.meshgrid(theta, r)
X = R * np.cos(T)
Y = R * np.sin(T)
Zup = np.sqrt(X**2 + Y**2)
ax.plot_surface(X, Y, Zup, rstride=1, cstride=1, linewidth=0,
antialiased=True,alpha=0.7,color='orange')
ax.plot_surface(X, Y, -Zup, rstride=1, cstride=1, linewidth=0,
antialiased=True,alpha=0.7,color='orange')
ax.set_axis_off()
ax.view_init(elev=4., azim=90.)
ax.dist=6
fig.tight_layout(pad=0.)
At certain angle (eg. azim=45
) both cones looks homogeneous but I would like them to have some ( consistent ) lighting. Thanks in advance.
Interesting, one has to change the bottom cone parameters to X[::-1], Y[::-1], -Zup[::-1]
to get the same shading as the top one. Full code below.
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure(figsize=(2,2.6));
ax = fig.add_subplot(111,projection='3d')
theta = np.linspace(0,2*np.pi,360)
r = np.linspace(0,1,100)
T, R = np.meshgrid(theta, r)
X = R * np.cos(T)
Y = R * np.sin(T)
Zup = np.sqrt(X**2 + Y**2)
ax.plot_surface(X, Y, Zup, rstride=1, cstride=1, linewidth=0,
antialiased=True,alpha=0.7,color='orange')
# fix here
# have to reverse the lists to get the same shading
ax.plot_surface(X[::-1], Y[::-1], -Zup[::-1], rstride=1, cstride=1,
linewidth=0, antialiased=True,alpha=0.7,color='orange')
ax.set_axis_off()
ax.view_init(elev=4., azim=90.)
ax.dist=6
fig.tight_layout(pad=0.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.