强制两个 matplotlib 3d 图在一个图中
forcing two matplotlib 3d plots to be in one figure
我怎样才能使它们重叠或合在一起(而不是并排):
fig = plt.figure()
ax = Axes3D(fig)
ax.set_xlim(-6, 6)
ax.set_ylim(-6, 6)
ax.set_zlim(-6, 6)
xx_floor, yy_floor, zz_floor = plot_plane(plane1['a'],
plane1['b'],
plane1['c'],
plane1['d'],
xwin=[-2, 2],
ywin=[-2, 2])
ax.plot_surface(xx_floor, yy_floor, zz_floor, color=(0, 1, 1, 0.3))
plane2_points = plane2[:3]
p0, p1, p2 = plane2_points
x0, y0, z0 = p0
x1, y1, z1 = p1
x2, y2, z2 = p2
ux, uy, uz = u = [x1 - x0, y1 - y0, z1 - z0]
vx, vy, vz = v = [x2 - x0, y2 - y0, z2 - z0]
u_cross_v = [uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx]
plane2_point = np.array(p0)
plane2_normal = np.array(u_cross_v)
pointdot = -plane2_point.dot(plane2_normal)
xx, yy = np.meshgrid(range(6), range(6))
z = (-plane2_normal[0] * xx - plane2_normal[1] * yy - pointdot) * 1. / plane2_normal[2]
plt3d = plt.figure().gca(projection='3d')
plt3d.plot_surface(xx, yy, z)
plt.show()
plt.close(fig=fig)
目前我看到两个图,我应该关闭第一个才能看到第二个。
fig = plt.figure()
ax = Axes3D(fig)
ax.set_xlim(-6, 6)
ax.set_ylim(-6, 6)
ax.set_zlim(-6, 6)
xx_floor, yy_floor, zz_floor = plot_plane(plane1['a'],
plane1['b'],
plane1['c'],
plane1['d'],
xwin=[-2, 2],
ywin=[-2, 2])
ax.plot_surface(xx_floor, yy_floor, zz_floor, color=(0, 1, 1, 0.3))
plane2_points = plane2[:3]
p0, p1, p2 = plane2_points
x0, y0, z0 = p0
x1, y1, z1 = p1
x2, y2, z2 = p2
ux, uy, uz = u = [x1 - x0, y1 - y0, z1 - z0]
vx, vy, vz = v = [x2 - x0, y2 - y0, z2 - z0]
u_cross_v = [uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx]
plane2_point = np.array(p0)
plane2_normal = np.array(u_cross_v)
pointdot = -plane2_point.dot(plane2_normal)
xx, yy = np.meshgrid(range(6), range(6))
z = (-plane2_normal[0] * xx - plane2_normal[1] * yy - pointdot) * 1. / plane2_normal[2]
#plt3d = plt.figure().gca(projection='3d')
#plt3d.plot_surface(xx, yy, z)
ax.plot_surface(xx, yy, z)
plt.show()
plt.close(fig=fig)
已按照 swatchai
的说明进行操作
我怎样才能使它们重叠或合在一起(而不是并排):
fig = plt.figure()
ax = Axes3D(fig)
ax.set_xlim(-6, 6)
ax.set_ylim(-6, 6)
ax.set_zlim(-6, 6)
xx_floor, yy_floor, zz_floor = plot_plane(plane1['a'],
plane1['b'],
plane1['c'],
plane1['d'],
xwin=[-2, 2],
ywin=[-2, 2])
ax.plot_surface(xx_floor, yy_floor, zz_floor, color=(0, 1, 1, 0.3))
plane2_points = plane2[:3]
p0, p1, p2 = plane2_points
x0, y0, z0 = p0
x1, y1, z1 = p1
x2, y2, z2 = p2
ux, uy, uz = u = [x1 - x0, y1 - y0, z1 - z0]
vx, vy, vz = v = [x2 - x0, y2 - y0, z2 - z0]
u_cross_v = [uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx]
plane2_point = np.array(p0)
plane2_normal = np.array(u_cross_v)
pointdot = -plane2_point.dot(plane2_normal)
xx, yy = np.meshgrid(range(6), range(6))
z = (-plane2_normal[0] * xx - plane2_normal[1] * yy - pointdot) * 1. / plane2_normal[2]
plt3d = plt.figure().gca(projection='3d')
plt3d.plot_surface(xx, yy, z)
plt.show()
plt.close(fig=fig)
目前我看到两个图,我应该关闭第一个才能看到第二个。
fig = plt.figure()
ax = Axes3D(fig)
ax.set_xlim(-6, 6)
ax.set_ylim(-6, 6)
ax.set_zlim(-6, 6)
xx_floor, yy_floor, zz_floor = plot_plane(plane1['a'],
plane1['b'],
plane1['c'],
plane1['d'],
xwin=[-2, 2],
ywin=[-2, 2])
ax.plot_surface(xx_floor, yy_floor, zz_floor, color=(0, 1, 1, 0.3))
plane2_points = plane2[:3]
p0, p1, p2 = plane2_points
x0, y0, z0 = p0
x1, y1, z1 = p1
x2, y2, z2 = p2
ux, uy, uz = u = [x1 - x0, y1 - y0, z1 - z0]
vx, vy, vz = v = [x2 - x0, y2 - y0, z2 - z0]
u_cross_v = [uy * vz - uz * vy, uz * vx - ux * vz, ux * vy - uy * vx]
plane2_point = np.array(p0)
plane2_normal = np.array(u_cross_v)
pointdot = -plane2_point.dot(plane2_normal)
xx, yy = np.meshgrid(range(6), range(6))
z = (-plane2_normal[0] * xx - plane2_normal[1] * yy - pointdot) * 1. / plane2_normal[2]
#plt3d = plt.figure().gca(projection='3d')
#plt3d.plot_surface(xx, yy, z)
ax.plot_surface(xx, yy, z)
plt.show()
plt.close(fig=fig)
已按照 swatchai