Automatic scroll
-
Hi guys I have a question regarding this code . I have taken this code from https://www.pythonguis.com/tutorials/plotting-pyqtgraph/. I want to know which part of code/code line is making graph to move in horizontal direction.
from PyQt5 import QtWidgets, QtCore
from pyqtgraph import PlotWidget, plot
import pyqtgraph as pg
import sys # We need sys so that we can pass argv to QApplication
import os
from random import randintclass MainWindow(QtWidgets.QMainWindow):
def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.graphWidget = pg.PlotWidget() self.setCentralWidget(self.graphWidget) self.x = list(range(100)) # 100 time points self.y = [randint(0,100) for _ in range(100)] # 100 data points self.graphWidget.setBackground('w') pen = pg.mkPen(color=(255, 0, 0)) self.data_line = self.graphWidget.plot(self.x, self.y, pen=pen) # ... init continued ... self.timer = QtCore.QTimer() self.timer.setInterval(50) self.timer.timeout.connect(self.update_plot_data) self.timer.start() def update_plot_data(self): self.x = self.x[1:] # Remove the first y element. self.x.append(self.x[-1] + 1) # Add a new value 1 higher than the last. self.y = self.y[1:] # Remove the first self.y.append( randint(0,100)) # Add a new random value. self.data_line.setData(self.x, self.y) # Update the data. app = QtWidgets.QApplication(sys.argv) w = MainWindow() w.show() sys.exit(app.exec_()) -
Hi guys I have a question regarding this code . I have taken this code from https://www.pythonguis.com/tutorials/plotting-pyqtgraph/. I want to know which part of code/code line is making graph to move in horizontal direction.
from PyQt5 import QtWidgets, QtCore
from pyqtgraph import PlotWidget, plot
import pyqtgraph as pg
import sys # We need sys so that we can pass argv to QApplication
import os
from random import randintclass MainWindow(QtWidgets.QMainWindow):
def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.graphWidget = pg.PlotWidget() self.setCentralWidget(self.graphWidget) self.x = list(range(100)) # 100 time points self.y = [randint(0,100) for _ in range(100)] # 100 data points self.graphWidget.setBackground('w') pen = pg.mkPen(color=(255, 0, 0)) self.data_line = self.graphWidget.plot(self.x, self.y, pen=pen) # ... init continued ... self.timer = QtCore.QTimer() self.timer.setInterval(50) self.timer.timeout.connect(self.update_plot_data) self.timer.start() def update_plot_data(self): self.x = self.x[1:] # Remove the first y element. self.x.append(self.x[-1] + 1) # Add a new value 1 higher than the last. self.y = self.y[1:] # Remove the first self.y.append( randint(0,100)) # Add a new random value. self.data_line.setData(self.x, self.y) # Update the data. app = QtWidgets.QApplication(sys.argv) w = MainWindow() w.show() sys.exit(app.exec_())@Crabnewbula said in Automatic scroll:
making graph to move in horizontal direction.
Presumably when you add a point on the timer expiry via
self.data_line.setData(self.x, self.y) # Update the data.if thatself.xis over at the right the graph auto-scrolls to show it?On a separate note: if you are going to show Python code it is vital you do so with correct indentation. I am guessing your actual code is not as shown, at least for
app = QtWidgets.QApplication(sys.argv)onward.