Skip to main contentIBM Quantum Documentation
This page is from an old version of Qiskit SDK Go to the latest version
Important

IBM Quantum Platform is moving and this version will be sunset on July 1. To get started on the new platform, read the migration guide.

plot_state_qsphere

plot_state_qsphere(rho, figsize=None, ax=None)

GitHub

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

  • rho (ndarray) – State vector or density matrix representation. of quantum state.
  • figsize (tuple) – Figure size in inches.
  • ax (matplotlib.axes.Axes) – An optional Axes object to be used for the visualization output. If none is specified a new matplotlib Figure will be created and used. Additionally, if specified there will be no returned Figure since it is redundant.

Returns

A matplotlib figure instance if the ax kwag is not set

Return type

Figure

Raises

ImportError – Requires matplotlib.

Example

from qiskit import QuantumCircuit, BasicAer, execute
from qiskit.visualization import plot_state_qsphere
%matplotlib inline
 
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])
 
backend = BasicAer.get_backend('statevector_simulator')
job = execute(qc, backend).result()
plot_state_qsphere(job.get_statevector(qc))

../_images/qiskit.visualization.plot_state_qsphere_0_2.png ../_images/qiskit.visualization.plot_state_qsphere_0_3.png

Was this page helpful?
Report a bug or request content on GitHub.