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種類のデータをプロットする方法

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

no image

matplotlib で折れ線グラフの下部に色をつけて塗りつぶす方法

pyplot の fill_between を使う。 例 from matplotlib import pyplot as plt data_x = [25,26,27] data_y = & …

no image

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

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

no image

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

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

no image

matplotlib でグラフの背景の色を変える方法(facecolor)

次のように、axes で facecolor を変更すればよい。 例 from matplotlib import pyplot as plt x = [2,7,8] y = [7,1 …