如何在使用QuTiP绘制Bloch球体时给出一个点标题

2024-06-28 18:54:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用QuTiP绘制一个Bloch球体图形。我想给它一个标题。我该怎么做?我在谷歌上搜索,但找不到答案。你知道吗


Tags: 答案图形标题绘制bloch球体qutip
1条回答
网友
1楼 · 发布于 2024-06-28 18:54:48

您需要在Matplotib中将Bloch球体渲染为三维图形中的轴。 下面是一个如何做到这一点的例子:

import matplotlib.pyplot as plt
import quitp

# needs Axes3D object to activate the '3d' projection
from mpl_toolkits.mplot3d import Axes3D

fig, ax = plt.subplots(figsize=(5, 5), subplot_kw=dict(projection='3d'))

ax.axis('square') # to get a nice circular plot

b1 = qutip.Bloch(fig=fig, axes=ax)
b1.add_states(qutip.sigmax()/2)
b1.zlabel = ['z', '']
b1.render(fig=fig, axes=ax) # render to the correct subplot 

# set title for the axis
ax.set_title('TITLE goes here', y=1.1, fontsize=20)

# You can anything else you want to the axis as well!
ax.annotate('TEXT', xy=(0.1, 0.9), xytext=(0.1, 0.7), xycoords='axes fraction',
            fontsize=15, color='r', ha='center',)

plt.show()

以下是输出:

enter image description here

理想情况下,一旦我们在对Bloch的调用中设置了figax,它就应该自动绘制到正确的轴上,但是render函数默认设置为fig=None, axis=None。这可能是个小虫子。你知道吗

相关问题 更多 >