57 lines
2.0 KiB
Plaintext
57 lines
2.0 KiB
Plaintext
---
|
||
title: plot_bloch_vector
|
||
description: API reference for qiskit.visualization.plot_bloch_vector
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: function
|
||
python_api_name: qiskit.visualization.plot_bloch_vector
|
||
---
|
||
|
||
# qiskit.visualization.plot\_bloch\_vector
|
||
|
||
<Function id="qiskit.visualization.plot_bloch_vector" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.21/qiskit/visualization/state_visualization.py" signature="plot_bloch_vector(bloch, title='', ax=None, figsize=None, coord_type='cartesian')">
|
||
Plot the Bloch sphere.
|
||
|
||
Plot a Bloch sphere with the specified coordinates, that can be given in both cartesian and spherical systems.
|
||
|
||
**Parameters**
|
||
|
||
* **bloch** (*list\[double]*) – array of three elements where \[\<x>, \<y>, \<z>] (Cartesian) or \[\<r>, \<theta>, \<phi>] (spherical in radians) \<theta> is inclination angle from +z direction \<phi> is azimuth from +x direction
|
||
* **title** (*str*) – a string that represents the plot title
|
||
* **ax** (*matplotlib.axes.Axes*) – An Axes to use for rendering the bloch sphere
|
||
* **figsize** (*tuple*) – Figure size in inches. Has no effect is passing `ax`.
|
||
* **coord\_type** (*str*) – a string that specifies coordinate type for bloch (Cartesian or spherical), default is Cartesian
|
||
|
||
**Returns**
|
||
|
||
A matplotlib figure instance if `ax = None`.
|
||
|
||
**Return type**
|
||
|
||
Figure
|
||
|
||
**Raises**
|
||
|
||
**MissingOptionalLibraryError** – Requires matplotlib.
|
||
|
||
**Examples**
|
||
|
||
```python
|
||
from qiskit.visualization import plot_bloch_vector
|
||
|
||
plot_bloch_vector([0,1,0], title="New Bloch Sphere")
|
||
```
|
||
|
||

|
||
|
||
```python
|
||
# You can use spherical coordinates instead of cartesian.
|
||
|
||
import numpy as np
|
||
|
||
plot_bloch_vector([1, np.pi/2, np.pi/3], coord_type='spherical')
|
||
```
|
||
|
||

|
||
</Function>
|
||
|