The following python 3.7 code allows to create animation files (as gif files) on a Bloch sphere using QuTip which is an open-source software based on Python for simulating the dynamics of open quantum systems.
import matplotlib as mpl
from pylab import *
from qutip import *
from matplotlib import cm
import imageio
def animate_bloch(states, duration=0.1, save_all=False):
b = Bloch()
b.vector_color = ['r']
b.view = [-40,30]
images=[]
try:
length = len(states)
except:
length = 1
states = [states]
## normalize colors to the length of data ##
nrm = mpl.colors.Normalize(0,length)
colors = cm.cool(nrm(range(length))) # options: cool, summer, winter, autumn etc.
## customize sphere properties ##
b.point_color = list(colors) # options: 'r', 'g', 'b' etc.
b.point_marker = ['o']
b.point_size = [30]
for i in range(length):
b.clear()
b.add_states(states[i])
b.add_states(states[:(i+1)],'point')
if save_all:
b.save(dirc='tmp') #saving images to tmp directory
filename="tmp/bloch_%01d.png" % i
else:
filename='temp_file.png'
b.save(filename)
images.append(imageio.imread(filename))
imageio.mimsave('bloch_anim.gif', images, duration=duration)
Create an animated file using state vectors
states = []
thetas = linspace(0,pi,21)
for theta in thetas:
states.append((cos(theta/2)*basis(2,0) + sin(theta/2)*basis(2,1)).unit())
animate_bloch(states, duration=0.1, save_all=False)
Below is the output file "bloch_anim.gif".
Plotting a single point using density matrix
states = ket2dm((basis(2,0) + 1j*basis(2,1)).unit())
animate_bloch(states, duration=0.1, save_all=False)
Below is the output png or gif file.