向表面添加光源

时间:2018-10-14 06:41:15

标签: python python-3.x graphics 3d

我有一个圆柱,我想添加光源。但是圆柱体背面的颜色不正确(应为黑色)。为什么?问题在哪里?

from matplotlib import pyplot as plt
import numpy as np
from matplotlib.colors import LightSource

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

x=np.linspace(-1, 1, 100)
z=np.linspace(0, 1, 100)
Xc, Zc=np.meshgrid(x, z)
Yc = np.sqrt(1-Xc**2)

############################
# Create light source object.
ls = LightSource(azdeg=0, altdeg=65)
# Shade data, creating an rgb array.
rgb = ls.shade(Yc, plt.cm.RdYlBu)

############################

rstride = 20
cstride = 10
ax.plot_surface(Xc, Yc, Zc,facecolors=rgb, alpha=0.9,linewidth=0)
ax.plot_surface(Xc, -Yc, Zc,facecolors=rgb, alpha=0.9,linewidth=0)

ax.set_xlabel("X")
ax.set_ylabel("Y")
ax.set_zlabel("Z")

plt.show()

0 个答案:

没有答案