probability_distribution

probability_distribution(data, figsize=(None, None), colors=None, scale='linear', number_to_keep=None, sort='asc', target_string=None, legend=None, bar_labels=True, state_labels_kind='bits', state_labels=None, title=None, plot_background_color='#e5e0df', background_color='#ffffff', as_widget=False)[source]

Interactive histogram plot of probability distributions.

Parameters
  • data (list or dict) – This is either a list of dictionaries or a single dict containing the values to represent (ex {‘001’: 130})

  • figsize (tuple) – Figure size in pixels.

  • colors (list or str) – String or list of strings for histogram bar colors.

  • scale (str) – Probability scale ‘linear’ (default) or ‘log’.

  • number_to_keep (int) – The number of terms to plot and rest is made into a single bar called ‘rest’.

  • sort (string) – Could be ‘asc’, ‘desc’, or ‘hamming’.

  • target_string (str) – Target string if ‘sort’ is a distance measure.

  • legend (list) – A list of strings to use for labels of the data. The number of entries must match the length of data (if data is a list or 1 if it’s a dict)

  • bar_labels (bool) – Label each bar in histogram with probability value.

  • state_labels_kind (str) – ‘bits’ (default) or ‘ints’.

  • state_labels (list) – A list of custom state labels.

  • title (str) – A string to use for the plot title.

  • plot_background_color (str) – Set the background color behind histogram bars.

  • background_color (str) – Set the background color for axes.

  • as_widget (bool) – Return figure as an ipywidget.

Returns

A figure for the rendered histogram.

Return type

PlotlyFigure or PlotlyWidget

Raises
  • ValueError – When legend is provided and the length doesn’t match the input data.

  • ImportError – When failed to load plotly.

  • KaleidoscopeError – When state labels is not correct length.

Example

from qiskit import *
import kaleidoscope.qiskit
from kaleidoscope.qiskit.services import Simulators
from kaleidoscope.interactive import probability_distribution

sim = Simulators.aer_vigo_simulator

qc = QuantumCircuit(3, 3) >> sim
qc.h(1)
qc.cx(1,0)
qc.cx(1,2)
qc.measure(range(3), range(3))

counts = qc.transpile().sample().result_when_done()
probability_distribution(counts)
Traceback (most recent call last):
  File "<ipython-input-1-fda3c4242931>", line 6, in <module>
    sim = Simulators.aer_vigo_simulator
  File "/opt/miniconda3/envs/qiskit/lib/python3.9/site-packages/kaleidoscope/qiskit/services/_simulators.py", line 190, in __getattr__
    raise AttributeError("Couldn't load {}.".format(attr))
AttributeError: Couldn't load aer_vigo_simulator.

Use %tb to get the full traceback.