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 で、縦横の罫線を引く方法

破線をカスタマイズする方法 以下では、dashes = [5,2,2,2] で、線5・空白2・線2・空白2の破線を指定している。 詳しくは次を参照。 https://matplotlib.org/st …

no image

matplotlib の ax でx軸、y軸の端の値を設定する

axes には、set_xlim として定義する。 例 import numpy as np from matplotlib import pyplot as plt x = np.linspace( …

no image

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

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

no image

matplotlib のプロットスクリプト内で計算する方法

gnuplot の場合 gnuplot では、plot “data.txt” u 1:($2*2)などと書くと、 数値を加工(データ値を使った計算)を行った結果をグラフ化するこ …

no image

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

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