0

Hi I'm looking for a program to find the maxima of multiple bands in a plot, yet I've found away to only localize the biggest maximum, I want to determine the coordinates of the second maximum.enter image description here

here is my script

`import numpy as np
import matplotlib.pyplot as plt

a2=np.loadtxt('O-25.txt') 
x2=a2[:,0]
y2=a2[:,1]
y2Max = max(y2)
print(y2Max)
zz = y2/y2Max




#plt.plot(x2,zz,linewidth=2,label="B3lyp")
fig, ax = plt.subplots()
ax.plot(x2,zz,linewidth=2,label="")


def annot_max(x2,zz, ax=None):
    xmax = x2[np.argmax(zz)]
    ymax = zz.max()
    text= "x={:.3f}, y={:.3f}".format(xmax, ymax)
    if not ax:
        ax=plt.gca()
    bbox_props = dict(boxstyle="square,pad=0.3", fc="w", ec="k", lw=0.72)
    arrowprops=dict(arrowstyle="->",connectionstyle="angle,angleA=0,angleB=60")
    kw = dict(xycoords='data',textcoords="axes fraction",
              arrowprops=arrowprops, bbox=bbox_props, ha="right", va="top")
    ax.annotate(text, xy=(xmax, ymax), xytext=(0.94,0.96), **kw)

annot_max(x2,zz)

plt.xlabel('wavelength(nm)' , fontname='arial', fontsize=14)
plt.ylabel('energy (cm-1)' , fontname='arial', fontsize=14)
plt.title("O-")
plt.legend()`
AIme999
  • 103
  • 2
  • 1
    One option is to take the calculus route, and try figure out the points where the rate of change between consecutive points is minimal. This will also of course give you minima as well. – Oxin Mar 04 '23 at 13:59

1 Answers1

0

You can locate all local maxima using scipy:

from scipy.signal import argrelextrema
inds_local_max = argrelextrema(zz, np.greater)
Thijs
  • 433
  • 8