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
- 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 [1;36m(most recent call last)[0m: File [0;32m"<ipython-input-1-fda3c4242931>"[0m, line [0;32m6[0m, in [0;35m<module>[0m sim = Simulators.aer_vigo_simulator [1;36m File [1;32m"/opt/miniconda3/envs/qiskit/lib/python3.9/site-packages/kaleidoscope/qiskit/services/_simulators.py"[1;36m, line [1;32m190[1;36m, in [1;35m__getattr__[1;36m[0m [1;33m raise AttributeError("Couldn't load {}.".format(attr))[0m [1;31mAttributeError[0m[1;31m:[0m Couldn't load aer_vigo_simulator. Use %tb to get the full traceback.