【问题标题】:Subplots with QuTip Bloch sphere带有 QuTip Bloch 球的子图
【发布时间】:2021-03-09 16:15:19
【问题描述】:

我想知道是否可以用两个子图绘制一个图形,其中一个是常规 2D 图,另一个是 Bloch 球体。

【问题讨论】:

    标签: matplotlib qutip subfigure


    【解决方案1】:

    是的,有可能。

    您需要手动创建figure 对象并使用matplotlib 的OO 接口将axes 添加到其中。在制作需要具有 Bloch 球体的轴时,您应该将投影设置为 3D。最后,只需在 Bloch 球体对象上调用 render 方法,以便将 Bloch 球体渲染到正确的子图

    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()
    

    【讨论】:

      猜你喜欢
      • 2014-11-11
      • 2020-05-10
      • 2018-10-23
      • 2019-05-28
      • 2022-11-06
      • 1970-01-01
      • 2020-07-18
      • 2014-07-30
      • 1970-01-01
      相关资源
      最近更新 更多