This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bloch sphere | |
# Amar Vutha, 2013-08-31 | |
from mpl_toolkits.mplot3d import Axes3D | |
import matplotlib.pyplot as plt | |
import numpy as np | |
# Basic Bloch sphere | |
fig = plt.figure() | |
ax = fig.add_subplot(111, projection='3d') | |
phi = np.linspace(0, 2 * np.pi, 40) | |
theta = np.linspace(0, np.pi, 60) | |
x = 1 * np.outer(np.cos(phi), np.sin(theta)) | |
y = 1 * np.outer(np.sin(phi), np.sin(theta)) | |
z = 1 * np.outer(np.ones(np.size(phi)), np.cos(theta)) | |
ax.plot_wireframe(x, y, z, rstride=10, cstride=30, color='gray', alpha=0.5) | |
ax.scatter([0],[0],[0],color='k',marker=r"\otimes",alpha=0.5) | |
# Annotate points | |
ax.text(0,0,1.2,r"|0\rangle") | |
ax.text(0,0,-1.2,r"|1\rangle") | |
ax.text(1.2,0,0,r"x") | |
ax.text(0,1.2,0,r"y") | |
# Set camera angle | |
ax.elev = 30 | |
ax.azim = 35 | |
# Plot points | |
theta0, phi0 = np.pi/2.3, 0 | |
ax.scatter([np.sin(theta0)*np.cos(phi0)],[np.sin(theta0)*np.sin(phi0)],[np.cos(theta0)],'bo') | |
plt.show() |