[matplotlib] 26. 非連続型水平棒グラフ

matplotlib

matplotlibで非連続な水平棒グラフ(broken_barh)

コード

解説

モジュールのインポート

図の作成、色の設定

ax.grid(axis=’y’)で横方向のグリッドを表示。

非連続な水平棒グラフの設定

ax.broken_barh([(70, 30), (130, 20), (170, 10)], (5, 5), facecolors=fcs)で、([(70, 30), (130, 20), (170, 10)]の意味は、x=70から30の長さの棒を伸ばす、x=130から20の長さの棒を伸ばす、x=170から10の長さの棒を伸ばすという意味になる。(5,5)は棒の幅の設定でy=5の位置から5の長さの棒を生やすこととなる。

facecolors=fcsは、色の設定でfcsのリスト通りに棒に色がつく。

コードをダウンロード(.pyファイル)

コードをダウンロード(.ipynbファイル)

参考

https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.broken_barh.html
https://matplotlib.org/gallery/lines_bars_and_markers/broken_barh.html?highlight=broken_barh

コメント