あなたの質問から、あなたがしたいことを100%明確にするわけではありません。
行のすべての頂点にラベルを付けるだけですか?または、整数だけの頂点にラベルを付けるだけですか?あるいは、整数 "交差点"が線に沿って並んでラベル付けする場所を補間したいですか?
最初に、テキストファイルを読み込むために、numpy.loadtxt
を探してください。最も簡単なオプションの簡単な例(全ての頂点を標識する)として、いずれにせよ
z, x, y = np.loadtxt('data.txt', usecols=[0, 5, 6]).T
:あなたの特定のケースでは、あなたのような何かができる
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(10)
y = 2 * x
z = x ** 2
fig, ax = plt.subplots()
ax.plot(x, y, 'bo-')
for X, Y, Z in zip(x, y, z):
# Annotate the points 5 _points_ above and to the left of the vertex
ax.annotate('{}'.format(Z), xy=(X,Y), xytext=(-5, 5), ha='right',
textcoords='offset points')
plt.show()
今
、 2番目の選択肢としては、私はこれと似た何かを持っているかもしれません(@ mathematical.coffeeと同様)。
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(-0.6, 5.6, 0.2)
y = 2 * x
z = x**2
fig, ax = plt.subplots()
ax.plot(x, y, 'bo-')
# Note the threshold... I'm assuming you want 1.000001 to be considered an int.
# Otherwise, you'd use "z % 1 == 0", but beware exact float comparisons!!
integers = z % 1 < 1e-6
for (X, Y, Z) in zip(x[integers], y[integers], z[integers]):
ax.annotate('{:.0f}'.format(Z), xy=(X,Y), xytext=(-10, 10), ha='right',
textcoords='offset points',
arrowprops=dict(arrowstyle='->', shrinkA=0))
plt.show()
これまでに何を試しましたか?言い換えれば、動作するものと動作しないもの(または失われた場所)を示すサンプルコードがありますか。質問を編集するときにコードを書式設定できることを覚えておいてください。 – Yann
何を試しましたか?これまでのコードをスニペットできますか? 'vals [vals%1 == 0]'は整数を検索し、['matplotlib.pyplot.text'](http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.text)を使うと、テキストを描画するすべての 'x、y'ペアに対して' plt.text(x、y、str(y)) 'を実行します。 –