Qiskitでヒストグラムを描画する(plot_histogram)

計算結果を可視化する手段としてヒストグラムは広く利用される。

Qiskitでヒストグラムをプロットするにはvisualizationモジュールに含まれるplot_histogram関数を使用する。

qiskit.visualization.plot_histogram — Qiskit 0.43.1 documentation

引数にはplot_histogram(Dict[str, int])のようにデータを辞書形式で与える。

from qiskit.visualization import plot_histogram

plot_histogram({'0': 898, '1': 126})

また、plot_histogram(List[Dict[str, int])のように複数のデータ群を与えることで複数のヒストグラムを並べて表示することもできる。

from qiskit.visualization import plot_histogram

plot_histogram(
    [
      {'00': 525, '11': 499},
      {'00': 511, '11': 514}
    ],
    legend=['First execution', 'Second execution'],
    color=['crimson','midnightblue'],
)