qiskit-documentation/docs/api/qiskit/0.38/qiskit.visualization.plot_s...

59 lines
2.8 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_state_hinton
description: API reference for qiskit.visualization.plot_state_hinton
in_page_toc_min_heading_level: 1
python_api_type: function
python_api_name: qiskit.visualization.plot_state_hinton
---
# qiskit.visualization.plot\_state\_hinton
<Function id="qiskit.visualization.plot_state_hinton" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.21/qiskit/visualization/state_visualization.py" signature="plot_state_hinton(state, title='', figsize=None, ax_real=None, ax_imag=None, *, rho=None, filename=None)">
Plot a hinton diagram for the density matrix of a quantum state.
The hinton diagram represents the values of a matrix using squares, whose size indicate the magnitude of their corresponding value and their color, its sign. A white square means the value is positive and a black one means negative.
**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.
* **filename** (*str*) file path to save image to.
* **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\_imag only the real 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 neither ax\_real or ax\_imag is set.
**Return type**
matplotlib.Figure
**Raises**
* **MissingOptionalLibraryError** Requires matplotlib.
* [**VisualizationError**](qiskit.visualization.VisualizationError "qiskit.visualization.VisualizationError") if input is not a valid N-qubit state.
**Examples**
```python
import numpy as np
from qiskit import QuantumCircuit
from qiskit.quantum_info import DensityMatrix
from qiskit.visualization import plot_state_hinton
qc = QuantumCircuit(2)
qc.h([0, 1])
qc.cz(0,1)
qc.ry(np.pi/3 , 0)
qc.rx(np.pi/5, 1)
state = DensityMatrix(qc)
plot_state_hinton(state, title="New Hinton Plot")
```
![../\_images/qiskit.visualization.plot\_state\_hinton\_0\_0.png](/images/api/qiskit/0.38/qiskit.visualization.plot_state_hinton_0_0.png)
</Function>