Probability Distribution Plotting
Functions for visualizing quantum measurement probability distributions as bar charts.
plot_probabilities
Unified interface for plotting probability distributions. Accepts either a dictionary mapping state labels to probabilities, or a list/array of probability values (which are automatically labeled with ket notation).
Signature
plot_probabilities(
data,
title: str = '',
figsize: Optional[tuple] = None,
top_k: Optional[int] = None,
save: Optional[str] = None
)Parameters
| Parameter | Type | Description |
|---|---|---|
| data | dict or list or array | Probability data. A dict maps state labels (e.g. '00', '11') to probabilities. A list/array is automatically labeled as |0>, |1>, ... |
| title | str | Plot title (default '') |
| figsize | tuple, optional | Figure size as (width, height) |
| top_k | int, optional | Only show the top K results with highest probability |
| save | str, optional | File path to save the plot image |
When data is a list or array, the keys are generated as \|0>, \|1>, \|2>, etc. When top_k is specified, only the K entries with the largest probability values are displayed.
Examples
from pyqpanda3.visualization import plot_probabilities
# From a dictionary (e.g. measurement results)
plot_probabilities({'00': 0.5, '11': 0.5})
# From a list of probabilities
plot_probabilities([0.25, 0.25, 0.25, 0.25])
# Show only top 3 results
plot_probabilities({'00': 0.4, '01': 0.3, '10': 0.2, '11': 0.1}, top_k=3)draw_probability
Draws a probability bar chart from a dictionary of quantum state labels and their probabilities. The probabilities are normalized so that their sum equals 1 before plotting.
Signature
draw_probability(list)Parameters
| Parameter | Type | Description |
|---|---|---|
| list | dict | A dictionary where keys are quantum state labels and values are their corresponding (unnormalized) probabilities |
Examples
from pyqpanda3.visualization import draw_probability
# Plot raw measurement counts (will be normalized)
draw_probability({'00': 500, '01': 50, '10': 50, '11': 400})draw_probability_dict
Draws a filtered probability bar chart. Unlike draw_probability, this function only displays entries whose probability is strictly greater than zero. Probabilities are normalized before plotting.
Signature
draw_probability_dict(prob_dict)Parameters
| Parameter | Type | Description |
|---|---|---|
| prob_dict | dict | A dictionary where keys are quantum state labels and values are their corresponding probabilities |
Examples
from pyqpanda3.visualization import draw_probability_dict
# Only non-zero probability states are displayed
draw_probability_dict({'00': 0.5, '01': 0.0, '10': 0.0, '11': 0.5})See Also
- visualization Module -- Circuit drawing and display configuration
- bloch.md -- Bloch sphere visualization