名称错误:未定义全局名称“PlotDataItem”

2024-05-03 08:59:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我想使用python中的pyqtgraph库绘制音频信号的振幅。我使用这里定义的PlotDataItem(xValues,yValues):http://www.pyqtgraph.org/documentation/graphicsItems/plotdataitem.html 所以在我的代码中,我创建了对象“plot”:

plot=PlotDataItem()

为了绘制x(长度)和y(num_data)值,我这样做:

^{pr2}$

我得到这个错误:

NameError: global name 'PlotDataItem' is not defined.

我不明白为什么,因为我以为“PlotDataItem”是在我导入的pyqtgraph库中定义的。 我不习惯python,所以我不熟悉这两行。在


Tags: orghttp定义信号plotdocumentationwww绘制
1条回答
网友
1楼 · 发布于 2024-05-03 08:59:56

你链接的文件说

Instances of PlotDataItem are usually created by plot() methods such as pyqtgraph.plot() and PlotItem.plot()

所以您必须导入pyqtgraph,然后像这样调用plot:

import pyqtgraph

plot = pyqtgraph.plot(length, num_data)

然后使用plot对象。在

相关问题 更多 >