qiskit-documentation/docs/api/qiskit/0.43/qiskit.visualization.plot_b...

88 lines
3.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_bloch_multivector
description: API reference for qiskit.visualization.plot_bloch_multivector
in_page_toc_min_heading_level: 1
python_api_type: function
python_api_name: qiskit.visualization.plot_bloch_multivector
---
<span id="qiskit-visualization-plot-bloch-multivector" />
# qiskit.visualization.plot\_bloch\_multivector
<Function id="qiskit.visualization.plot_bloch_multivector" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.24/qiskit/visualization/state_visualization.py" signature="plot_bloch_multivector(state, title='', figsize=None, *, rho=None, reverse_bits=False, filename=None, font_size=None, title_font_size=None, title_pad=1)">
Plot a Bloch sphere for each qubit.
Each component $(x,y,z)$ of the Bloch sphere labeled as qubit i represents the expected value of the corresponding Pauli operator acting only on that qubit, that is, the expected value of $I_{N-1} \otimes\dotsb\otimes I_{i+1}\otimes P_i \otimes I_{i-1}\otimes\dotsb\otimes I_0$, where $N$ is the number of qubits, $P\in \{X,Y,Z\}$ and $I$ is the identity operator.
<Admonition title="Deprecated since version 0.15.1" type="danger">
`qiskit.visualization.state_visualization.plot_bloch_multivector()`s argument `rho` is deprecated as of qiskit-terra 0.15.1. It will be removed no earlier than 3 months after the release date. Instead, use the argument `state`, which behaves identically.
</Admonition>
**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*) size of each individual Bloch sphere figure, in inches.
* **reverse\_bits** (*bool*) If True, plots qubits following Qiskits convention \[Default:False].
* **font\_size** (*float*) Font size for the Bloch ball figures.
* **title\_font\_size** (*float*) Font size for the title.
* **title\_pad** (*float*) Padding for the title (suptitle y position is y=1+title\_pad/100).
**Returns**
A matplotlib figure instance.
**Return type**
[`matplotlib.figure.Figure`](https://matplotlib.org/stable/api/figure_api.html#matplotlib.figure.Figure "(in Matplotlib v3.7.2)")
**Raises**
* **MissingOptionalLibraryError** Requires matplotlib.
* [**VisualizationError**](qiskit.visualization.VisualizationError "qiskit.visualization.VisualizationError") if input is not a valid N-qubit state.
**Examples**
```python
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
from qiskit.visualization import plot_bloch_multivector
qc = QuantumCircuit(2)
qc.h(0)
qc.x(1)
state = Statevector(qc)
plot_bloch_multivector(state)
```
![../\_images/qiskit-visualization-plot\_bloch\_multivector-1.png](/images/api/qiskit/0.43/qiskit-visualization-plot_bloch_multivector-1.png)
```python
from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector
from qiskit.visualization import plot_bloch_multivector
qc = QuantumCircuit(2)
qc.h(0)
qc.x(1)
# You can reverse the order of the qubits.
from qiskit.quantum_info import DensityMatrix
qc = QuantumCircuit(2)
qc.h([0, 1])
qc.t(1)
qc.s(0)
qc.cx(0,1)
matrix = DensityMatrix(qc)
plot_bloch_multivector(matrix, title='My Bloch Spheres', reverse_bits=True)
```
![../\_images/qiskit-visualization-plot\_bloch\_multivector-2.png](/images/api/qiskit/0.43/qiskit-visualization-plot_bloch_multivector-2.png)
</Function>