0
我有以下脚本读取两列ascii文件并生成1D图。该图有几个峰值。我想要的是给所有的峰值,如第一个峰值1,第二个峰值2等等。峰值出现在X轴的等距位置上。有人能告诉我如何在Python中做到这一点。代码 -给出高峰数字的阴谋
from pylab import*
# Read the file.
f2 = open('d012_SAXS-recomb.txt', 'r')
# read the whole file into a single variable, which is a list of every row of the file.
lines = f2.readlines()[2:-100]
f2.close()
# initialize some variable to be lists:
x1 = []
y1 = []
# scan the rows of the file stored in lines, and put the values into some variables:
for line in lines:
p = line.split()
x1.append(float(p[0]))
y1.append(float(p[1]))
x = np.array(x1)
y = np.array(y1)
xlim(0.0,4.0)
# now, plot the data:
#subplot(211)
plt.plot(x, y, color='orange',linewidth=2.0, linestyle='-', label='Arabic - LPP''\nRoman - SPP''\nAsterisk - CHOL')
legend(loc='upper right')
xlabel('q')
ylabel('Intensity')
plt.show()
您是否在讨论如何计算正确的位置来使用pyplot.text()放置一些文本,如“peak1”,“peak2”等?语法是pyplot.text(x,y,string)。 – Stuart 2013-03-05 13:23:14
您的问题更多地涉及如何找到高峰,还是更关联如何放置文本? – Stuart 2013-03-05 13:28:35
pyplot.text可以做到这一点,但在这种情况下,我必须手动给出每个峰的x,y坐标,以便将数字1,2,3置于其上。有没有什么方法可以自动找到峰高并在峰顶放置1,2,3等数字? – user2095624 2013-03-05 14:24:52