【发布时间】:2023-03-19 20:15:01
【问题描述】:
我正在尝试使用 pyQtGraph 绘制实时图表(关于股票交易演变的图表)并且有一些我无法解决的问题检查示例:
我希望图表从左到右开始绘制(这是默认情况下发生的情况)并且当它到达边界框的右侧而不是调整它的大小以使所有新数据适合我希望它滚动使新数据从右侧输入,旧数据从左侧消失。
我知道将数据附加到 numpy 数组会创建数组的新实例。我不想要这个。有没有办法告诉 pyQtGraph plot 只获取 numpy 数组范围内的数据?例如,我可以最初实例化一个包含 10000 个浮点数的数组并告诉 pyQtGraph 只绘制前 100 个浮点数吗?
另一方面,我发现我可以就地修改数组并移动数字来模拟滚动。有什么方法可以让 pyQtGraph 使用 numpy 数组作为环?这样我只需要告诉图表从索引开始,一切都可以在没有分配的情况下工作,等等......
这是我到目前为止的代码,非常简单:
class Grapher(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
self.graphicsView.setTitle('My Graph')
self.graphicsView.setLabel('bottom', 'X axis')
self.graphicsView.setLabel('left', 'Y axis')
self.graphicsView.setLimits(xMin=0, yMin=0)
self.graphicsView.showGrid(x=True, y=True)
self.x=np.array();
self.y=np.array();
self._timer=QtCore.QTimer()
self._timer.timeout.connect(self.update)
self._timer.start(1000)
self._timerCounter=0;
def update(self):
self.x=np.append(self.x, [self._timerCounter]);
self.y=np.append(self.y, [math.sin(self._timerCounter)])
self.graphicsView.plot(self.x, self.y)
self._timerCounter+=1;
提前致谢。
【问题讨论】:
-
显示你的代码!!!
标签: arrays python-3.x numpy pyqt5 pyqtgraph