Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
203 views
in Technique[技术] by (71.8m points)

python - forcing two matplotlib 3d plots to be in one figure

How can I make these to be overlapping or be together in one figure (not side by side):

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)

Currently, I see two figures that I should close the first one to see the second one.

enter image description here

question from:https://stackoverflow.com/questions/65911457/forcing-two-matplotlib-3d-plots-to-be-in-one-figure

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
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)

Followed the instructions by swatchai

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...