カラーバー
    Colorbar
    Top > Python > 描画 > 一般
    matplotlib.pyplot.colorbar
     よく使う引数と稀に使う引数について。  ここに載っていない引数やキーワード、また細かい仕様については公式ドキュメントを参照。 + matplotlib.pyplot.colorbar — Matplotlib 3.1.1 documentation colorbar(aspect, pad, shrink, orientation, extend, extendfrac) aspect : 縦横比 pad : 図との間隔 shrink : 図の隣接する軸との長さの比 orientation: 鉛直 ('vertical') か水平 ('horizontal')か extend : 範囲外の値を表示するか ('neither', 'both', 'min', 'max') extendfrac : 範囲外部分の長さ extendrect : 範囲外部分を四角形にする (True, False)
    基本的な使い方
    例1. matplotlib.pyplot.imshow  例2. matplotlib.pyplot.scatter
    カラーバーのみを描く
    範囲外の値
    オプショナル引数のextendを指定する。 連続なカラーマップ 不連続なカラーマップでも同じ。
    目盛
    グラフの軸と同様、目盛の位置とラベルを設定できる。 matplotlib.axes.Axes.tick_params matplotlib.axes.Axes.set_ticks matplotlib.axes.Axes.set_ticklabels を使う。 例として上の図をインデックスによる色分け風に変えてみる。。 目盛の位置を各色のレンジの中央に設定し、ラベルをインデックス('A', 'B', ...)に置き換える。 また目盛線があると汚いので消す(tick_params)。 カラーバーが縦なのでtick_paramsのaxisは'y'とする。水平の時は'x'とする。同様にright='off'はbottom='off'とする。 ラベルの文字サイズはlabelsizeで与える。
    References
    matplotlib.pyplot.colorbar — Matplotlib 3.1.1 documentation + https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.colorbar.html Customized Colorbars Tutorial — Matplotlib 3.1.1 documentation + https://matplotlib.org/3.1.1/tutorials/colors/colorbar_only.html matplotlib.axes.Axes.tick_params — Matplotlib 3.1.1 documentation + https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.axes.Axes.tick_params.html matplotlib.axis.Axis.set_ticks — Matplotlib 3.1.0 documentation + https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.axis.Axis.set_ticks.html matplotlib.axis.Axis.set_ticklabels — Matplotlib 3.1.1 documentation + https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.axis.Axis.set_ticklabels.html