Sorunuzdan, tam olarak ne yapmak istediğinizi tam olarak% 100 değilim.
Her tepe noktasını bir satırda etiketlemek mi istiyorsunuz? Yoksa sadece tamsayı olan köşeleri etiketlemek mi istiyorsunuz? Veya tamsayı "geçişlerin" satır boyunca hizalanacağı ve bunları etiketleyeceği yerlere mi geçmek istiyorsunuz? Zaten değilseniz
Öncelikle, metin dosyasının yüklenmesi için, numpy.loadtxt
içine bakmak. En basit seçenek hızlı bir örnek (her köşe etiketleme) gibi herhangi bir oranda
z, x, y = np.loadtxt('data.txt', usecols=[0, 5, 6]).T
: sizin özel durumda, böyle bir şey yapabileceğini
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()
Şimdi
, ikinci seçenek için, bunun gibi daha fazla bir şeye sahip olabiliriz (@ mathematical.coffee önerisine benzer):
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()
Şimdiye kadar denedim ne var? Başka bir deyişle, neyin işe yarayıp neyin işe yaramadığını gösteren bir örnek kodunuz var mı (ya da nerede kaybettiğiniz). Sorunuzu düzenlerken kodu biçimlendirebileceğinizi unutmayın ... – Yann
Ne denediniz? Şu ana kadar bir kod pasajı verebilir misiniz? vals [vals% 1 == 0] 'tamsayıları bulur ve [' matplotlib.pyplot.text'] 'i kullanabilirsiniz (http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.text) metin çizmek için. Tüm x, y 'çiftleri için' plt.text (x, y, str (y)) '. –