Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2156 code of Bloch animation in doc #2409

Merged
merged 2 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/changes/2409.doc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix #2156
Correct a sample of code in the doc
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>`_