plot()返回一个有用的对象:
[<matplotlib.lines.Line2D object at 0x38c9910>]
从中,我们可以获得x和y轴的值:
import matplotlib.pyplot as plt, numpy as np...line2d = plt.plot(xnew,heights_smooth)xvalues = line2d[0].get_xdata()yvalues = line2d[0].get_ydata()
然后,我们可以获得宽度值之一的索引:
idx = np.where(xvalues==xvalues[-2]) # this is 179.3979933110368# idx is a tuple of array(s) containing index where value was found# in this case -> (array([298]),)
以及相应的高度:
yvalues[idx]# -> array([ 315.53469])
要检查,我们可以使用
get_xydata():
>>> xy = line2d[0].get_xydata()>>> xy[-2]array([ 179.39799331, 315.53469 ])



