Posts

Showing posts with the label Matplotlib

Find max Y value from matplotlib.pyplot

8.2.2018 Find max Y value from matplotlib.pyplot import matplotlib.pyplot as plt import numpy as np file = open('tesffile.txt', 'w') dt = 0.01 t = np.arange(0, 10, dt) nse = np.random.randn(len(t)) r = np.exp(-t/0.05) cnse = np.convolve(nse, r)*dt cnse = cnse[:len(t)] s = 0.1*np.sin(2*np.pi*t) + cnse plt.psd(s, 64, 1/dt) plt.title('Plot') plt.xlabel('X') plt.ylabel('Y') plt.grid(True) ax = plt.gca() line = ax.lines[0] ydata = line.get_ydata() xdata = line.get_xdata() ymax = -999999 imax = -1 i = 0 while i < len(ydata):     if ydata[i] > ymax:         ymax = ydata[i]         imax = i     print(xdata[i], ydata[i])     s = str(xdata[i])     s += ' '     s += str(ydata[i])     s += '\r\n'     file.write(s)     i += 1 print print xdata[imax], ymax file.close() plt.show()