qiskit-documentation/docs/api/qiskit/0.24/qiskit.visualization.pulse_...

114 lines
5.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: pulse_drawer
description: API reference for qiskit.visualization.pulse_drawer
in_page_toc_min_heading_level: 1
python_api_type: function
python_api_name: qiskit.visualization.pulse_drawer
---
<span id="qiskit-visualization-pulse-drawer" />
# qiskit.visualization.pulse\_drawer
<Function id="qiskit.visualization.pulse_drawer" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.16/qiskit/visualization/pulse_visualization.py" signature="pulse_drawer(data, dt=1, style=None, filename=None, interp_method=None, scale=None, channel_scales=None, plot_all=False, plot_range=None, interactive=False, table=False, label=False, framechange=True, channels=None, show_framechange_channels=True)">
Plot the interpolated envelope of pulse and schedule.
**Parameters**
* **data** (`Union`\[`Waveform`, `ScheduleComponent`]) Pulse or schedule object to plot.
* **dt** (`int`) Time interval of samples. Pulses are visualized in the unit of cycle time if not provided.
* **style** (`Union`\[[`PulseStyle`](qiskit.visualization.pulse.qcstyle#pulsestyle "qiskit.visualization.pulse.qcstyle.PulseStyle"), [`SchedStyle`](qiskit.visualization.pulse.qcstyle#schedstyle "qiskit.visualization.pulse.qcstyle.SchedStyle"), `None`]) A style sheet to configure plot appearance. See [`qcstyle`](qiskit.visualization.pulse.qcstyle#module-qiskit.visualization.pulse.qcstyle "qiskit.visualization.pulse.qcstyle") for more information.
* **filename** (`Optional`\[`str`]) Name required to save pulse image. The drawer just returns matplot.Figure object if not provided.
* **interp\_method** (`Optional`\[`Callable`]) Interpolation function. Interpolation is disabled in default. See [`interpolation`](qiskit.visualization.pulse.interpolation#module-qiskit.visualization.pulse.interpolation "qiskit.visualization.pulse.interpolation") for more information.
* **scale** (`Optional`\[`float`]) Scaling of waveform amplitude. Pulses are automatically scaled channel by channel if not provided.
* **channel\_scales** (`Optional`\[`Dict`\[[`Channel`](qiskit.pulse.channels#channel "qiskit.pulse.channels.Channel"), `float`]]) Dictionary of scale factor for specific channels. Scale of channels not specified here is overwritten by scale.
* **plot\_all** (`bool`) When set True plot empty channels.
* **plot\_range** (`Optional`\[`Tuple`\[`Union`\[`int`, `float`], `Union`\[`int`, `float`]]]) A tuple of time range to plot.
* **interactive** (`bool`) When set True show the circuit in a new window. This depends on the matplotlib backend being used supporting this.
* **table** (`bool`) When set True draw event table for supported commands.
* **label** (`bool`) When set True draw label for individual instructions.
* **framechange** (`bool`) When set True draw framechange indicators.
* **channels** (`Optional`\[`List`\[[`Channel`](qiskit.pulse.channels#channel "qiskit.pulse.channels.Channel")]]) A list of channel names to plot. All non-empty channels are shown if not provided.
* **show\_framechange\_channels** (`bool`) When set True plot channels with only framechange instructions.
**Returns**
A matplotlib figure object for the pulse envelope.
**Return type**
matplotlib.figure.Figure
**Example**
This example shows how to visualize your pulse schedule. Pulse names are added to the plot, unimportant channels are removed and the time window is truncated to draw out U3 pulse sequence of interest.
```python
import numpy as np
import qiskit
from qiskit import pulse
from qiskit.test.mock.backends.almaden import FakeAlmaden
inst_map = FakeAlmaden().defaults().instruction_schedule_map
sched = pulse.Schedule()
sched += inst_map.get('u3', 0, np.pi, 0, np.pi)
sched += inst_map.get('measure', list(range(20))) << sched.duration
channels = [pulse.DriveChannel(0), pulse.MeasureChannel(0)]
scales = {pulse.DriveChannel(0): 10}
qiskit.visualization.pulse_drawer(sched,
channels=channels,
plot_range=(0, 1000),
label=True,
channel_scales=scales)
```
![../\_images/qiskit.visualization.pulse\_drawer\_0\_0.png](/images/api/qiskit/0.24/qiskit.visualization.pulse_drawer_0_0.png)
You are also able to call visualization module from the instance method:
```python
sched.draw(channels=channels, plot_range=(0, 1000), label=True, channel_scales=scales)
```
To customize the format of the schedule plot, you can setup your style sheet.
```python
import numpy as np
import qiskit
from qiskit import pulse
from qiskit.test.mock.backends.almaden import FakeAlmaden
inst_map = FakeAlmaden().defaults().instruction_schedule_map
sched = pulse.Schedule()
sched += inst_map.get('u3', 0, np.pi, 0, np.pi)
sched += inst_map.get('measure', list(range(20))) << sched.duration
# setup style sheet
my_style = qiskit.visualization.SchedStyle(
figsize = (10, 5),
bg_color='w',
d_ch_color = ['#32cd32', '#556b2f'])
channels = [pulse.DriveChannel(0), pulse.MeasureChannel(0)]
scales = {pulse.DriveChannel(0): 10}
qiskit.visualization.pulse_drawer(sched, style=my_style,
channels=channels,
plot_range=(0, 1000),
label=True,
channel_scales=scales)
```
![../\_images/qiskit.visualization.pulse\_drawer\_1\_0.png](/images/api/qiskit/0.24/qiskit.visualization.pulse_drawer_1_0.png)
**Raises**
* [**VisualizationError**](qiskit.visualization.VisualizationError "qiskit.visualization.VisualizationError") when invalid data is given
* **ImportError** when matplotlib is not installed
</Function>