Skip to content

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

python
plot_probabilities(
    data,
    title: str = '',
    figsize: Optional[tuple] = None,
    top_k: Optional[int] = None,
    save: Optional[str] = None
)

Parameters

ParameterTypeDescription
datadict or list or arrayProbability data. A dict maps state labels (e.g. '00', '11') to probabilities. A list/array is automatically labeled as |0>, |1>, ...
titlestrPlot title (default '')
figsizetuple, optionalFigure size as (width, height)
top_kint, optionalOnly show the top K results with highest probability
savestr, optionalFile 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

python
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

python
draw_probability(list)

Parameters

ParameterTypeDescription
listdictA dictionary where keys are quantum state labels and values are their corresponding (unnormalized) probabilities

Examples

python
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

python
draw_probability_dict(prob_dict)

Parameters

ParameterTypeDescription
prob_dictdictA dictionary where keys are quantum state labels and values are their corresponding probabilities

Examples

python
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

Released under the MIT License.