Skip to main contentIBM Quantum Documentation

qiskit.visualization.plot_state_city

qiskit.visualization.plot_state_city(state, title='', figsize=None, color=None, alpha=1, ax_real=None, ax_imag=None, *, filename=None) GitHub(opens in a new tab)

Plot the cityscape of quantum state.

Plot two 3d bar graphs (two dimensional) of the real and imaginary part of the density matrix rho.

Parameters

  • state (Statevector orDensityMatrix or ndarray) – an N-qubit quantum state.
  • title (str(opens in a new tab)) – a string that represents the plot title
  • figsize (tuple(opens in a new tab)) – Figure size in inches.
  • color (list(opens in a new tab)) – A list of len=2 giving colors for real and imaginary components of matrix elements.
  • alpha (float(opens in a new tab)) – Transparency value for bars
  • ax_real (matplotlib.axes.Axes(opens in a new tab)) – An optional Axes object to be used for the visualization output. If none is specified a new matplotlib Figure will be created and used. If this is specified without an ax_imag only the real component plot will be generated. Additionally, if specified there will be no returned Figure since it is redundant.
  • ax_imag (matplotlib.axes.Axes(opens in a new tab)) – An optional Axes object to be used for the visualization output. If none is specified a new matplotlib Figure will be created and used. If this is specified without an ax_real only the imaginary component plot will be generated. Additionally, if specified there will be no returned Figure since it is redundant.

Returns

The matplotlib.Figure of the visualization if the ax_real and ax_imag kwargs are not set

Return type

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

Raises

Examples

# You can choose different colors for the real and imaginary parts of the density matrix.
 
from qiskit import QuantumCircuit
from qiskit.quantum_info import DensityMatrix
from qiskit.visualization import plot_state_city
 
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
 
state = DensityMatrix(qc)
plot_state_city(state, color=['midnightblue', 'crimson'], title="New State City")
../_images/qiskit-visualization-plot_state_city-1.png
# You can make the bars more transparent to better see the ones that are behind
# if they overlap.
 
import numpy as np
from qiskit.quantum_info import Statevector
from qiskit.visualization import plot_state_city
from qiskit import QuantumCircuit
 
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)
 
state = Statevector(qc)
plot_state_city(state, alpha=0.6)
../_images/qiskit-visualization-plot_state_city-2.png
Was this page helpful?