qiskit-documentation/docs/api/qiskit/1.2/qiskit.visualization.plot_c...

65 lines
2.6 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: plot_circuit_layout (v1.2)
description: API reference for qiskit.visualization.plot_circuit_layout in qiskit v1.2
in_page_toc_min_heading_level: 1
python_api_type: function
python_api_name: qiskit.visualization.plot_circuit_layout
---
<span id="qiskit-visualization-plot-circuit-layout" />
# qiskit.visualization.plot\_circuit\_layout
<Function id="qiskit.visualization.plot_circuit_layout" isDedicatedPage={true} github="https://github.com/Qiskit/qiskit/tree/stable/1.2/qiskit/visualization/gate_map.py#L1142-L1246" signature="qiskit.visualization.plot_circuit_layout(circuit, backend, view='virtual', qubit_coordinates=None)">
Plot the layout of a circuit transpiled for a given target backend.
**Parameters**
* **circuit** ([*QuantumCircuit*](qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")) Input quantum circuit.
* **backend** ([*Backend*](qiskit.providers.Backend "qiskit.providers.Backend")) Target backend.
* **view** ([*str*](https://docs.python.org/3/library/stdtypes.html#str "(in Python v3.13)"))
How to label qubits in the layout. Options:
* `"virtual"`: Label each qubit with the index of the virtual qubit that mapped to it.
* `"physical"`: Label each qubit with the index of the physical qubit that it corresponds to on the device.
* **qubit\_coordinates** (*Sequence*) An optional sequence input (list or array being the most common) of 2d coordinates for each qubit. The length of the sequence must match the number of qubits on the backend. The sequence should be the planar coordinates in a 0-based square grid where each qubit is located.
**Returns**
A matplotlib figure showing layout.
**Return type**
Figure
**Raises**
* [**QiskitError**](exceptions#qiskit.exceptions.QiskitError "qiskit.exceptions.QiskitError") Invalid view type given.
* [**VisualizationError**](visualization#qiskit.visualization.VisualizationError "qiskit.visualization.VisualizationError") Circuit has no layout attribute.
**Example**
```python
from qiskit import QuantumCircuit, transpile
from qiskit.providers.fake_provider import GenericBackendV2
from qiskit.visualization import plot_circuit_layout
ghz = QuantumCircuit(3, 3)
ghz.h(0)
for idx in range(1,3):
ghz.cx(0,idx)
ghz.measure(range(3), range(3))
backend = GenericBackendV2(num_qubits=5)
new_circ_lv3 = transpile(ghz, backend=backend, optimization_level=3)
plot_circuit_layout(new_circ_lv3, backend)
```
![../\_images/qiskit-visualization-plot\_circuit\_layout-1.png](/images/api/qiskit/1.2/qiskit-visualization-plot_circuit_layout-1.avif)
</Function>