概要
matplotlib で x 軸、y 軸のラベル、タイトルを設定する方法を紹介します。
x 軸、y 軸のラベル、タイトル
- pyplot.xlabel: x 軸のラベルを取得または設定する
- pyplot.ylabel: y 軸のラベルを取得または設定する
- axes.Axes.get_xlabel: x 軸のラベルを取得する
- axes.Axes.set_xlabel: x 軸のラベルを設定する
- axes.Axes.get_ylabel: y 軸のラベルを取得する
- axes.Axes.set_ylabel: y 軸のラベルを設定する
- pyplot.title: タイトルを取得または設定する
- axes.Axes.get_title: タイトルを取得する
- axes.Axes.set_title: タイトルを設定する
In [1]:
get_xlabel() height (cm) get_ylabel() frequency get_title() stature distribution

ラベルのパラメータを設定する
ラベルのフォントサイズ、色など matplotlib.text.Text のパラメータを指定できます。
パラメータ名 | 内容 | 値 |
---|---|---|
alpha | 透過度 | float |
color / c | フォントの色 | COLOR |
fontfamily / family | フォントファミリー | {FONTNAME, ‘serif’, ‘sans-serif’, ‘cursive’, ‘fantasy’, ‘monospace’} |
fontsize / size | フォントサイズ | float or {‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’} |
fontstyle / style | フォントスタイル | {‘normal’, ‘italic’, ‘oblique’} |
rotation | 回転 | float or {‘vertical’, ‘horizontal’} |
In [2]:

ラベルの位置を揃える
1つの図に複数のグラフがある場合、x 軸、y 軸のラベルはデフォルトでは整列されません。
このラベルを整列したい場合は、Figure.align_labels()
を呼び出します。
In [3]:

コメント