Skip to main contentIBM Quantum Documentation

qiskit.visualization.plot_state_qsphere

qiskit.visualization.plot_state_qsphere(state, figsize=None, ax=None, show_state_labels=True, show_state_phases=False, use_degrees=False, *, filename=None)

Plot the qsphere representation of a quantum state. Here, the size of the points is proportional to the probability of the corresponding term in the state and the color represents the phase.

Parameters

Returns

A matplotlib figure instance if the ax kwarg is not set

Return type

matplotlib.figure.Figure (opens in a new tab)

Raises


Examples

from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
from qiskit.visualization import plot_state_qsphere
 
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
 
state = Statevector(qc)
plot_state_qsphere(state)
../_images/qiskit-visualization-plot_state_qsphere-1.png
# You can show the phase of each state and use
# degrees instead of radians
 
from qiskit.quantum_info import DensityMatrix
import numpy as np
from qiskit import QuantumCircuit
from qiskit.visualization import plot_state_qsphere
 
qc = QuantumCircuit(2)
qc.h([0, 1])
qc.cz(0,1)
qc.ry(np.pi/3, 0)
qc.rx(np.pi/5, 1)
qc.z(1)
 
matrix = DensityMatrix(qc)
plot_state_qsphere(matrix,
     show_state_phases = True, use_degrees = True)
../_images/qiskit-visualization-plot_state_qsphere-2.png
Was this page helpful?