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 で2種類のcsvファイルをプロットする方法

data1.csv と、data2.csv の2つのファイルを散布図としてプロットするには次のようにする。 例 import numpy as np from matplotlib import py …

no image

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

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

no image

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

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

no image

matplotlib で、x,y の軸上の数値を表示する方法

ax の xtics と ytics を使って表示する。 詳細は次のドキュメントを参照。 https://matplotlib.org/stable/gallery/lines_bars_and_ma …

no image

matplotlib で、凡例を表示する方法

データに label を関連付け、plt.legend() で凡例を表示する。 例 from matplotlib import pyplot as plt data_x = [25,26,2 …