60 lines
3.0 KiB
Plaintext
60 lines
3.0 KiB
Plaintext
---
|
||
title: plot_state_city
|
||
description: API reference for qiskit.visualization.plot_state_city
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: function
|
||
python_api_name: qiskit.visualization.plot_state_city
|
||
---
|
||
|
||
# qiskit.visualization.plot\_state\_city
|
||
|
||
<Function id="qiskit.visualization.plot_state_city" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.18/qiskit/visualization/state_visualization.py" signature="plot_state_city(state, title='', figsize=None, color=None, alpha=1, ax_real=None, ax_imag=None, *, rho=None)">
|
||
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*](qiskit.quantum_info.Statevector "qiskit.quantum_info.Statevector") *or*[*DensityMatrix*](qiskit.quantum_info.DensityMatrix "qiskit.quantum_info.DensityMatrix") *or ndarray*) – an N-qubit quantum state.
|
||
* **title** (*str*) – a string that represents the plot title
|
||
* **figsize** (*tuple*) – Figure size in inches.
|
||
* **color** (*list*) – A list of len=2 giving colors for real and imaginary components of matrix elements.
|
||
* **alpha** (*float*) – Transparency value for bars
|
||
* **ax\_real** (*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. 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*) – 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
|
||
|
||
**Raises**
|
||
|
||
* [**MissingOptionalLibraryError**](qiskit.aqua.MissingOptionalLibraryError "qiskit.aqua.MissingOptionalLibraryError") – Requires matplotlib.
|
||
* **ValueError** – When ‘color’ is not a list of len=2.
|
||
* [**VisualizationError**](qiskit.visualization.VisualizationError "qiskit.visualization.VisualizationError") – if input is not a valid N-qubit state.
|
||
|
||
**Example**
|
||
|
||
```python
|
||
from qiskit import QuantumCircuit
|
||
from qiskit.quantum_info import DensityMatrix
|
||
from qiskit.visualization import plot_state_city
|
||
%matplotlib inline
|
||
|
||
qc = QuantumCircuit(2)
|
||
qc.h(0)
|
||
qc.cx(0, 1)
|
||
|
||
state = DensityMatrix.from_instruction(qc)
|
||
plot_state_city(state, color=['midnightblue', 'midnightblue'],
|
||
title="New State City")
|
||
```
|
||
|
||

|
||
</Function>
|
||
|