-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
Short description
As per discussion at https://groups.google.com/g/pyqtgraph/c/5TMt_vC-lUI, when I draw a line graph that contains invalid points, the valid points either side of the invalid region are sometimes connected by a straight line. I would expect that the line should stop before the invalid region and start again afterwards.
Code to reproduce
import sys
from PySide6 import QtWidgets, QtCore
import pyqtgraph as pg
import logging
class SENSORDemo(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
# central widget
central_widget = QtWidgets.QWidget()
# create widgets
self.update_timer = QtCore.QTimer()
plot_box = QtWidgets.QGroupBox()
plot_box_layout = QtWidgets.QGridLayout()
self.halt_graph_update = QtWidgets.QCheckBox("Update graphs")
self.halt_graph_update.setChecked(True)
pg.setConfigOption("background", "w")
pg.setConfigOption("foreground", "k")
pos_plot_widget = pg.GraphicsLayoutWidget()
vel_plot_widget = pg.GraphicsLayoutWidget()
pos_plot = pos_plot_widget.addPlot(title="P")
vel_plot = vel_plot_widget.addPlot(title="V")
# pos_plot = self.plot.addPlot(row=0, col=0)
# vel_plot = self.plot.addPlot(row=0, col=1)
pos_plot.getViewBox().setMouseMode(pg.ViewBox.RectMode)
pos_plot.getViewBox().setMouseEnabled(x=False, y=True)
pos_plot.getViewBox().setLimits(xMin=0, xMax=1024, minXRange=1024)
pos_plot.getAxis("left").setStyle(
autoExpandTextSpace=True, autoReduceTextSpace=False
)
vel_plot.getViewBox().setMouseMode(pg.ViewBox.RectMode)
vel_plot.getViewBox().setMouseEnabled(x=False, y=True)
vel_plot.getViewBox().setLimits(xMin=0, xMax=1024, minXRange=1024)
vel_plot.getAxis("left").setStyle(
autoExpandTextSpace=True, autoReduceTextSpace=False
)
self.pos_plot_line = pos_plot.plot()
self.vel_plot_line = vel_plot.plot()
plot_box_layout.addWidget(
self.halt_graph_update, 0, 0, 1, 2, QtCore.Qt.AlignCenter
)
plot_box_layout.addWidget(pos_plot_widget, 2, 0, 1, 1)
plot_box_layout.addWidget(vel_plot_widget, 2, 1, 1, 1)
plot_box.setLayout(plot_box_layout)
# layout widgets
central_layout = QtWidgets.QGridLayout()
central_layout.addWidget(plot_box, 4, 0, 1, 2)
central_widget.setLayout(central_layout)
self.setCentralWidget(central_widget)
# connect signals/slots
self.update_timer.timeout.connect(self.update_position)
self.update_timer.start(1000)
@QtCore.Slot()
def update_position(self):
if self.halt_graph_update.isChecked():
samples = [x % 10 if x < 100 or x > 150 else float("nan") for x in range(1024)]
self.pos_plot_line.setData(
[x for x in samples],
pen=(0, 0, 255),
)
self.vel_plot_line.setData(
[x for x in samples],
pen=(0, 0, 255),
)
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
app = QtWidgets.QApplication(sys.argv)
app.setApplicationName("Read Sensor")
sensordemo = SENSORDemo()
sensordemo.resize(800, 600)
sensordemo.show()
sys.exit(app.exec())Expected behavior
Invalid region should have no line drawn across it
Real behavior
A line is drawn across the invalid region of the graph (between x=100 and x=150).

Changing the zoom level using the mouse causes the graph to redraw correctly (until the next call to setData()).
Tested environment(s)
- PyQtGraph version: 0.12.4
- Qt Python binding: PySide6 6.3.1 Qt 6.3.1
- Python version: 3.10.4
- NumPy version: 1.22.4
- Operating system: Windows 11
- Installation method: pip
Additional context
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels