matplotlib

matplotlib で、グラフ内に注釈ラベルをつける方法

投稿日:

annotate を使う

import numpy as np
import matplotlib.pyplot as plt

ax = plt.figure().add_subplot()
theta = np.linspace(-0 * np.pi, 3 * np.pi, 100)
# パラメータープロット
x = np.sin(theta)
y = np.cos(theta)
ax.set_xlim([-2,2])

ax.plot(x, y, label='parametric curve')
ax.legend()

# ラベル(annotation)をつける部分
ax.annotate("Test", xy=(0.7, 0.3), xycoords=ax.transAxes,
bbox=dict(boxstyle="round,pad=0.3", fc="white", ec="red"))

plt.show()

結果

-matplotlib
-

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

matplotlib で、y軸に二種類の軸を設定する方法

y軸に、2種類のグラフを異なるスケールでプロットする。 matplotlib axes の twinx() を使う。 https://matplotlib.org/stable/api/_as_gen …

no image

matplotlib で、グラフの点の見た目を変更する方法

「marker」で指定すればよい。 次のページを参考に、plotの「marker」を変更する。 https://matplotlib.org/stable/api/markers_api.html 例 …

no image

matplotlib でエラーバーを設定する方法

pyplot.errorbar を使って設定する。 オプションの詳細は https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.erro …

no image

matplotlib でグラフの中に注釈の文字を書く方法

annotate を使う。 例 import numpy as np from matplotlib import pyplot as plt x = np.linspace(-10,10,100) …

no image

matplotlib で目盛りに文字を使用する方法

文字に tex の記法を使って数式を入力することもできる。 例 import numpy as np from matplotlib import pyplot as plt x = np.linsp …