qbraid.visualization.plot_distribution

plot_distribution(counts, legend=None, colors=None, title=None, x_label=None, y_label=None, show_plot=True, save_path=None)[source]

Plots a histogram probability distribution of quantum states.

Parameters:
  • counts (Union[list[Dict], Dict]) – Dictionary or a list of dictionaries containing the quantum states as keys and their respective counts as values.

  • legend (Optional[Union[list[str], str]]) – List of strings or a single string representing the labels of the datasets. Defaults to None, where it generates default labels.

  • colors (Optional[Union[list[str], str]]) – List of strings or a single string representing the colors for each dataset. Defaults to None, where it generates a color sequence.

  • title (Optional[str]) – String representing the title of the plot. Defaults to None.

  • x_label (Optional[str]) – String representing the label for the x-axis. Defaults to None.

  • y_label (Optional[str]) – String representing the label for the y-axis. Defaults to None.

  • show_plot (Optional[bool]) – Boolean representing whether to show the plot. Defaults to True.

  • save_path (Optional[str]) – String representing the path to save the plot. Defaults to None.

Returns:

This function does not return a value; it displays a plot.

Return type:

None

Raises:

ValueError – Raises an error if input arguments do not match the expected types or formats.

Example

counts_dict1 = {'00': 50, '01': 30, '10': 10, '11': 10}
counts_dict2 = {'00': 20, '01': 40, '10': 30, '11': 10}

plot_distribution(
    counts=[counts_dict1, counts_dict2],
    legend=['First Execution', 'Second Execution'],
    colors=['crimson', 'midnightblue'],
    title="Quantum State Probability Distribution",
    x_label="Quantum States",
    y_label="Probabilities"
)