Skip to main contentIBM Quantum Documentation
You are viewing the API reference for an old version of Qiskit SDK. Switch to latest version

qiskit.visualization.plot_state_paulivec

qiskit.visualization.plot_state_paulivec(state, title='', figsize=None, color=None, ax=None, *, filename=None) GitHub(opens in a new tab)

Plot the Pauli-vector representation of a quantum state as bar graph.

The Pauli-vector of a density matrix ρ\rho is defined by the expectation of each possible tensor product of single-qubit Pauli operators (including the identity), that is

ρ=12nσ{I,X,Y,Z}nTr(σρ)σ.\rho = \frac{1}{2^n} \sum_{\sigma \in \{I, X, Y, Z\}^{\otimes n}} \mathrm{Tr}(\sigma \rho) \sigma.

This function plots the coefficients Tr(σρ)\mathrm{Tr}(\sigma\rho) as bar graph.

Parameters

Returns

The matplotlib.Figure of the visualization if the ax kwarg is not set

Return type

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

Raises

Examples

# You can set a color for all the bars.
 
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
from qiskit.visualization import plot_state_paulivec
 
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
 
state = Statevector(qc)
plot_state_paulivec(state, color='midnightblue', title="New PauliVec plot")
../_images/qiskit-visualization-plot_state_paulivec-1.png
# If you introduce a list with less colors than bars, the color of the bars will
# alternate following the sequence from the list.
 
import numpy as np
from qiskit.quantum_info import DensityMatrix
from qiskit import QuantumCircuit
from qiskit.visualization import plot_state_paulivec
 
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
 
qc = QuantumCircuit(2)
qc.h([0, 1])
qc.cz(0, 1)
qc.ry(np.pi/3, 0)
qc.rx(np.pi/5, 1)
 
matrix = DensityMatrix(qc)
plot_state_paulivec(matrix, color=['crimson', 'midnightblue', 'seagreen'])
../_images/qiskit-visualization-plot_state_paulivec-2.png
Was this page helpful?
Report a bug or request content on GitHub.