<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Automatic scroll]]></title><description><![CDATA[<p dir="auto">Hi guys I have a question regarding this code . I have taken this code from <a href="https://www.pythonguis.com/tutorials/plotting-pyqtgraph/" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.pythonguis.com/tutorials/plotting-pyqtgraph/</a>. I want to know which part of  code/code line is making graph to move in horizontal direction.</p>
<p dir="auto">from PyQt5 import QtWidgets, QtCore<br />
from pyqtgraph import PlotWidget, plot<br />
import pyqtgraph as pg<br />
import sys  # We need sys so that we can pass argv to QApplication<br />
import os<br />
from random import randint</p>
<p dir="auto">class MainWindow(QtWidgets.QMainWindow):</p>
<pre><code>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_())
</code></pre>
]]></description><link>https://forum.qt.io/topic/138141/automatic-scroll</link><generator>RSS for Node</generator><lastBuildDate>Wed, 08 Apr 2026 02:14:12 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/138141.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 25 Jul 2022 07:40:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Automatic scroll on Mon, 25 Jul 2022 08:12:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/crabnewbula">@<bdi>Crabnewbula</bdi></a> said in <a href="/post/722528">Automatic scroll</a>:</p>
<blockquote>
<p dir="auto">making graph to move in horizontal direction.</p>
</blockquote>
<p dir="auto">Presumably when you add a point on the timer expiry via <code>self.data_line.setData(self.x, self.y)  # Update the data.</code> if that <code>self.x</code> is over at the right the graph auto-scrolls to show it?</p>
<p dir="auto">On a separate note: if you are going to show Python code it is <em>vital</em> you do so with correct indentation.  I am guessing your actual code is <em>not</em> as shown, at least for <code>app = QtWidgets.QApplication(sys.argv)</code> onward.</p>
]]></description><link>https://forum.qt.io/post/722536</link><guid isPermaLink="true">https://forum.qt.io/post/722536</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Mon, 25 Jul 2022 08:12:07 GMT</pubDate></item></channel></rss>