It is always useful to check the documentation: https://qiskit.org/documentation/_modules/qiskit/visualization/state_visualization.html You can see there the source code for all visualization tools in qiskit.visualization
.
The function plot_bloch_multivector
is somehow factorizing the state and converting the statevector data into products of individual qubit vectors in the Bloch sphere.
The steps are the following, import the factorization routine called _bloch_multivector_data
as follows:
from qiskit.visualization.utils import _bloch_multivector_data
and then store the data of your multivector called state
as
bloch_data = (_bloch_multivector_data(state))
each bloch_data[i]
, for i
=0,1,2,3 has three entries with correspond to the i
-th qubit in Cartesian coordinates ($x,y,z$), which can be used to get the angles.
For example if you chose qubit 2
qubitvector=bloch_data[2]
then its coordinates are :
qubitvector_x=qubitvector[0]
for $x$,
qubitvector_y=qubitvector[1]
for $y$,
qubitvector_z=qubitvector[2]
for $z$.
The angles can be retrieved by looking at the definition of the spherical coordinates (in a unit sphere):
- the azimuthal angle is given by $\tan \varphi = y/x$, and
- the polar angle is given by $\cos \theta = z$.
Disclaimer: this procedure works only for products of single qubit states. This procedure will not work if you use any entangling gates (gates that apply to more than one qubit like CNOT) in your quantum circuit.