我尝试使用名为searchsorted
的numpy
方法,但我无法使其工作。
以下是代码:
class Object(QMainWindow):
def __init__(self):
QMainWindow.__init(self)
self.figure_canvas = FigureCanvas(Figure())
self.axes = self.figure_canvas.add_subplot(111)
x = np.arange(0.0, 5.0, 0.01)
y = np.sin(2*np.pi*x) + 0.5*np.random.randn(len(x))
self.axes.plot(x, y, "-", picker = 5)
self.axes.set_ylim(-2, 2)
def onselect(xmin, xmax):
indmin, indmax = np.searchsorted(x, (xmin, xmax)
当我尝试构建这段代码时,出现以下错误:
NameError: global name 'x' is not defined
问题在哪里?我定义了要使用的x,但它显示未被定义。
希望你能帮助我。
)
。 - pp_