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 で、グラフの線の幅を変更する方法

lw で、線幅を数字で指定すればよい。 例 from matplotlib import pyplot as plt data_x = [25,26,27] data_y = [39, …

no image

matplotlib で、2種類のデータをプロットする方法

下では、凡例(legend)を設定している。 例 from matplotlib import pyplot as plt data_x = [25,26,27] data_y = [ …

no image

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

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

no image

matplotlib で散布グラフを描く方法

pyplt.scatter を使って散布グラフを描くことができる。 点の色は、点ごとに変えることができる。 下の例では color の配列で点の色を指定している。 例 from matplotlib …

no image

matplotlib でcsv ファイルを読み込むとき、最初の行をスキップする方法

numpy の loadtxt で読み込む行を省略したい場合 スキップしたい行を # 等の記号でコメントアウトして、 loadtxt の comments = ‘#’ とすると …