2
$\begingroup$

I am able to visualize vectors on a bloch sphere using Qiskit as follows:

from qiskit.quantum_info import Statevector
from qiskit.visualization import plot_bloch_vector
%matplotlib inline

sv = []
sv.append([0,1,0])
sv.append([0,0,1])
sv.append([1,0,0])

fig = plot_bloch_vector(sv)
fig

The code above yields the following result (which looks good):

enter image description here

Now I would like to adjust the colors of each vector. The API of Qiskit seems not to provide any color parameter for plot_bloch_vector. Maybe we can manipulate the fig object directly or find another way to adjust vector colors?

$\endgroup$

1 Answer 1

5
$\begingroup$

A simple way to do that is by using Bloch class[1] directly which accepts a list of vector colors to cycle through:

from qiskit.visualization.bloch import Bloch

_bloch = Bloch()
_bloch.vector_color = ['red', 'green', 'blue']

sv = []
sv.append([1,0,0])
sv.append([0,1,0])
sv.append([0,0,1])

_bloch.add_vectors(sv)
_bloch.render()
_bloch.fig

The result:

enter image description here

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.