Function Repository Resource:

BlochSpherePlot

Source Notebook

Plot the Bloch sphere

Contributed by: Mohammad Bahrami

ResourceFunction["BlochSpherePlot"][]

plots a labeled Bloch sphere.

ResourceFunction["BlochSpherePlot"][{x,y,z}]

plots a labeled Bloch sphere together with the Bloch vector {x,y,z}∈ℝ3.

ResourceFunction["BlochSpherePlot"][{{x1,y1,z1},,{xn,yn,zn}}]

shows multiple vectors in 3.

ResourceFunction["BlochSpherePlot"][{α,β}]

plots a labeled Bloch sphere together with the Bloch vector of the quantum state {α,β}∈ℂ2.

ResourceFunction["BlochSpherePlot"][{{α1,β1},,{αn,βn}}]

shows multiple quantum states in 2.

ResourceFunction["BlochSpherePlot"][ρ]

plots a labeled Bloch sphere together with the Bloch vector of the quantum density matrix ρ∈ℂ2⊗ℂ2.

ResourceFunction["BlochSpherePlot"][{ρ1,,ρn}]

plots a labeled Bloch sphere together with Bloch vectors of quantum density matrices ρi∈ℂ2⊗ℂ2.

Details and Options

The Bloch sphere is a way to draw any single qubit (2-level quantum system) as a point on a unit sphere.
For a generic qubit state vector {α,β} with α,β∈ℂ, assumed to be normalized α2+β2=1, the Bloch vector is defined as .
For a qubit state denoted by a 2×2 density matrix ρ, the Bloch vector is defined as . The density matrix ρ should be explicitly positive semidefinite.
ResourceFunction["BlochSpherePlot"] can take options of Graphics3D. Additionally, the following options can be given:
"NumberOfGreatCircles"2number of great circles (also called parallels) whose centers are the same as the sphere’s center
"ShowGreatCircles"Trueif False, the great circles will not be shown
"NumberOfSmallCircles"1number of small circles (also called meridians) whose centers are along z-axis
"ShowSmallCircles"Trueif False, the small circles will not be shown
"Labels"Automaticlabels of axes, based on common kets for the eigenstates of Pauli operators. If it is set as "Optics" the common optics labels as will be used.
"LabelPositions"Automaticpositions of labels in the Bloch sphere
"ShowLabels"Trueif False, axes labels will not be shown
"ShowAxes"Trueif False, the customized axes will not be shown
"ForceStateVector"Falseif True, the input is interpreted as state vector

Examples

Basic Examples (7) 

Plot the Bloch sphere:

In[1]:=
ResourceFunction["BlochSpherePlot"][]
Out[1]=

Plot the Bloch sphere for a Bloch vector:

In[2]:=
ResourceFunction["BlochSpherePlot"][{1/2, Sqrt[1/2], 1/2}]
Out[2]=

Plot the Bloch sphere for some random Bloch vectors:

In[3]:=
ResourceFunction["BlochSpherePlot"][RandomPoint[Sphere[], 4]]
Out[3]=

Plot the Bloch sphere for the quantum state {Cos[π/6],-π/4Sin[π/6]}:

In[4]:=
ResourceFunction[
 "BlochSpherePlot"][{Cos[\[Pi]/6], -E^(I \[Pi]/4) Sin[\[Pi]/6]}]
Out[4]=

Plot the Bloch sphere for a list of random pure quantum states:

In[5]:=
ResourceFunction["BlochSpherePlot"][
 First /@ RandomVariate[CircularUnitaryMatrixDistribution[2], 3]]
Out[5]=

Plot the Bloch sphere for a random density matrix:

In[6]:=
ResourceFunction[
 "BlochSpherePlot"][{1/
    2 (IdentityMatrix[2] + RandomPoint[Ball[]] . Table[PauliMatrix[j], {j, 3}])}]
Out[6]=

Plot the Bloch sphere for a list of random density matrices:

In[7]:=
ResourceFunction["BlochSpherePlot"][
 Table[1/2 (IdentityMatrix[2] + RandomPoint[Ball[]] . Table[PauliMatrix[j], {j, 3}]), 5]]
Out[7]=

Options (10) 

Add more great circles (also called parallels):

In[8]:=
ResourceFunction["BlochSpherePlot"]["NumberOfGreatCircles" -> 4]
Out[8]=

Turn off great circles:

In[9]:=
ResourceFunction["BlochSpherePlot"]["ShowGreatCircles" -> False]
Out[9]=

Add more small circles (also called meridians):

In[10]:=
ResourceFunction["BlochSpherePlot"]["NumberOfSmallCircles" -> 4]
Out[10]=

Turn off small circles:

In[11]:=
ResourceFunction["BlochSpherePlot"]["ShowSmallCircles" -> False]
Out[11]=

Show common labels in optics:

In[12]:=
ResourceFunction["BlochSpherePlot"]["Labels" -> "Optics"]
Out[12]=

Show customized labels:

In[13]:=
ResourceFunction["BlochSpherePlot"][
 "Labels" -> {{"x1", "x2"}, {"y1", "y2"}, {"z1", "z2"}}]
Out[13]=

Customize labels positions:

In[14]:=
ResourceFunction["BlochSpherePlot"][
 "LabelPositions" -> {{1, -2}, {2, -1}, {2, -1}}]
Out[14]=

Turn off labels:

In[15]:=
ResourceFunction["BlochSpherePlot"]["ShowLabels" -> False]
Out[15]=

Do not show axes:

In[16]:=
ResourceFunction["BlochSpherePlot"]["ShowAxes" -> False]
Out[16]=

Force the state vector interpretation:

In[17]:=
ResourceFunction["BlochSpherePlot"][IdentityMatrix[2], "ForceStateVector" -> True]
Out[17]=

Applications (2) 

Given an initial quantum state, plot the state after bit-flip and phase-flip errors:

In[18]:=
\[Psi]0 = {Cos[\[Pi]/8], Exp[I \[Pi]/3] Sin[\[Pi]/8]};
ResourceFunction[
 "BlochSpherePlot"][{\[Psi]0, PauliMatrix[3] . \[Psi]0, PauliMatrix[2] . \[Psi]0}]
Out[19]=

Given the initial Bloch vector {0,0,1}, plot the state rotation around y-axis by the angles {π/6,π/3,2π/3}:

In[20]:=
ResourceFunction["BlochSpherePlot"][
 Table[RotationTransform[\[Theta], {0, 1, 0}][{0, 0, 1}], {\[Theta], {\[Pi]/6, \[Pi]/3, 2 \[Pi]/3}}]]
Out[20]=

Possible Issues (3) 

The input should be a list of vectors as {x,y,z}ϵ ℝ2, or state vectors {α,β}∈ ℂ2 or density matrices:

In[21]:=
ResourceFunction["BlochSpherePlot"][{1}]
Out[21]=

If the states are out of the Bloch sphere, it means they are not physically accessible states:

In[22]:=
ResourceFunction["BlochSpherePlot"][{1.8, 0, 0}]
Out[22]=

A list of two state vectors can be also interpreted as a density matrix, such as {{1,0},{0,1}}:

In[23]:=
ResourceFunction["BlochSpherePlot"][IdentityMatrix[2]]
Out[23]=

Force the state vector interpretation:

In[24]:=
ResourceFunction["BlochSpherePlot"][IdentityMatrix[2], "ForceStateVector" -> True]
Out[24]=

Neat Examples (1) 

Plot a generic pure state as {Cos[θ/2],ⅈ ϕSin[θ/2]}:

In[25]:=
Manipulate[
 ResourceFunction[
  "BlochSpherePlot"][{Cos[\[Theta]/2], Sin[\[Theta]/2] Exp[I \[Phi]]}], {\[Theta], 0, \[Pi]}, {\[Phi], 0, 2 \[Pi]}, SaveDefinitions -> True]
Out[25]=

Publisher

Mads Bahrami

Version History

  • 1.0.0 – 24 November 2025

Related Resources

Author Notes

This function is an extended version of a similar feature we have in the Wolfram quantum framework.

License Information