Skip to content

Commit

Permalink
Fix qutip#2156 code of Bloch animation in doc
Browse files Browse the repository at this point in the history
  • Loading branch information
PositroniumJS committed Apr 25, 2024
1 parent 63f1478 commit 23d0792
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions doc/guide/guide-bloch.rst
Original file line number Diff line number Diff line change
Expand Up @@ -323,25 +323,19 @@ Directly Generating an Animation
The code to directly generate an mp4 movie of the Qubit decay is as follows ::

from matplotlib import pyplot, animation
from mpl_toolkits.mplot3d import Axes3D

fig = pyplot.figure()
ax = Axes3D(fig, azim=-40, elev=30)
ax = fig.add_subplot(azim=-40, elev=30, projection="3d")
sphere = qutip.Bloch(axes=ax)

def animate(i):
sphere.clear()
sphere.add_vectors([np.sin(theta), 0, np.cos(theta)])
sphere.add_vectors([np.sin(theta), 0, np.cos(theta)], ["r"])
sphere.add_points([sx[:i+1], sy[:i+1], sz[:i+1]])
sphere.make_sphere()
return ax

def init():
sphere.vector_color = ['r']
return ax

ani = animation.FuncAnimation(fig, animate, np.arange(len(sx)),
init_func=init, blit=False, repeat=False)
ani = animation.FuncAnimation(fig, animate, np.arange(len(sx)), blit=False, repeat=False)
ani.save('bloch_sphere.mp4', fps=20)

The resulting movie may be viewed here: `bloch_decay.mp4 <https://raw.githubusercontent.com/qutip/qutip/master/doc/figures/bloch_decay.mp4>`_

0 comments on commit 23d0792

Please sign in to comment.