pyqtgraph不会显示全部数据

问题描述 投票:0回答:1

我正在运行一个python程序来实时绘制声音。我基本上是在遵循一般教程,但是没有正确绘制它。信封:python2.7,pyside + pyqtgraph,windows10,anaconda venv

我的代码如下:

# coding:utf-8

import numpy as np
import sys

import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui

import pyaudio

sample_rate = 16000
frame_length = 1024
frame_shift = 80


class PlotWindow:
    def __init__(self):

        self.win = pg.GraphicsWindow()
        self.win.setWindowTitle("realtime plotting")
        self.win.resize(1100, 400)
        self.plt = self.win.addPlot(title="updating_plot")  
        pg.setConfigOptions(antialias=True)
        #self.ymin = -1000
        #self.ymax = 1000
        self.plt.setYRange(-1.0, 1.0)  
        self.curve = self.plt.plot(pen='y')  

        self.CHUNK = frame_length  
        self.RATE = sample_rate  
        self.audio = pyaudio.PyAudio()
        self.stream = self.audio.open(format=pyaudio.paInt16,
                                      channels=1,
                                      rate=self.RATE,
                                      input=True,
                                      output=True,
                                      frames_per_buffer=self.CHUNK)



        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.update)
        self.timer.start(5) 

        self.data = np.zeros(self.CHUNK)

    def update(self):
        self.data = self.AudioInput()
        self.curve.setData(self.data)


    def AudioInput(self):
        ret = self.stream.read(self.CHUNK)
        ret = np.frombuffer(ret, dtype="int16") / 32768
        numpydata = self.stream.read(self.CHUNK)
        numpydata = np.fromstring(numpydata, dtype=np.int16)
        #print("RET", ret)
        #print("NUMPYDATA", numpydata)
        return numpydata


if __name__ == "__main__":
    plotwin = PlotWindow()

    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()

并且绘制的图像是这样的。似乎顶部已以某种方式修剪,并且无法显示全部数据。

绘图图像

“”

即使使用超级简单的代码版本,其行为也相同。

app = QApplication(sys.argv)
data = [10,20,30,40,50,60,70,80,90,100]
pg.plot(data)
sys.exit(app.exec_())

绘图图像

“”

python pyside pyaudio pyqtgraph
1个回答
0
投票

请正确尝试此代码。

import sys

import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui

app = QtGui.QApplication(sys.argv)
data = [10,20,30,40,50,60,70,80,90,100]
pg.plot(data)
sys.exit(app.exec_())

在我的机器(Linux,Python 3.6,pyqtgraph 0.10.0)上,这看起来很好:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.