【发布时间】:2022-11-23 21:35:30
【问题描述】:
基本上,我在 Python 中循环生成光线,并试图将它们全部绘制在同一张图上。它们都应该在半径为 0.1 的圆上。每条射线都应位于圆上的某个位置,该位置随 arg 的变化而变化,在本例中为 theta。另外,只是提一下(虽然我不认为它是相关的)我在这里做 OOP。
我得到了正确的光线,但我无法在同一个 3d 图上得到它们,而且我不确定我应该怎么做。我以为使用 plt.show() 会给我一个包含所有 24 条射线的图表,但它只绘制了 24 个图表。 这是相关的代码供参考:
r = 0.1
arg = 0
for i in range (0,24):
arg += np.pi/12
x = r*np.sin(arg)
y = r*np.cos(arg)
l = ray.Ray(r=np.array([x,y,0]),v=np.array([0.5,0,5]))
c = ray.SphericalRefraction(z0 = 100, curv = 0.0009, n1 = 1.0, n2 = 1.5, ar = 5)
c.propagate_ray(l)
o = ray.OutputPlane(250)
o.outputintercept(l)
points = np.array(l.vertices())
fig = plt.figure()
ax = plt.axes(projection='3d')
#ax = fig.add_subplot(1,2,1,projection='3d')
#plt.plot(points[:,2],points[:,0])
ax.plot3D(points[:,0],points[:,1],points[:,2])
plt.show()
【问题讨论】:
-
这是因为您调用了 figure() 24 次。摆脱循环。
-
我试过了,现在它给我这样的错误: toolbar = getattr(self.figure.canvas, "toolbar") AttributeError: 'NoneType' 对象没有属性 'canvas'
标签: python matplotlib 3d raytracing