我想知道是否可以用两个子图来绘制一个图形,其中一个是常规的2D图,另一个是Bloch球面。
发布于 2021-03-26 19:45:32
是的,这是可能的。
您需要手动创建figure对象,并使用matplotlib的OO接口将axes添加到该对象。在制作需要具有Bloch球体的轴时,应将投影设置为3D。最后,只需在Bloch sphere对象上调用render方法,就可以将Bloch sphere呈现到正确的子图中
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
fig = plt.figure(constrained_layout=True)
ax1 = fig.add_subplot(1, 2, 1)
ax1.plot(range(10), range(10), "o-")
ax2 = fig.add_subplot(1, 2, 2, projection='3d')
b1 = q.Bloch(fig=fig, axes=ax2)
b1.render(fig=fig, axes=ax2)
ax2.set_box_aspect([1, 1, 1]) # required for mpl > 3.1
plt.show()

https://stackoverflow.com/questions/65027865
复制相似问题