[Python] PySide6: PyQtGraph scatterplot not loading data spots correctly, it displays all spot...

Discussão em 'Python' iniciado por Stack, Julho 21, 2025.

  1. Stack

    Stack Membro Participativo

    I am working on a PySide6 application and am implementing a PyQtGraph in a layout. I want to use PyQtGraph instead of Matplotlib because apperently it would be better to use it for interactive graph (e.g. clicking on a data spot in the graph to do (activate method) X, Y and Z). unfortunatley when I try and add data to the pyqtgraph.ScatterPlotItem class and then add it in to the pyqtgraph.PLotwidget. I see the data spots but it is stuck on the top-left corner of the graph.

    I have tried:

    • searching for solutions online
    • simplefying the code by directly adding params (like spots data) directly to the pyqtgraph.ScatterPlotItem (class), instead of creating a instance of the class and individually calling a method for each attribute (e.g. setData, setSize)
    • Tried changing layout where graph is displayed

    I was not able to get this issue resolved by searching online because the PySide6 community apprently is not that big, and ChatGTP could not help me out with this one.

    class ScatterPlotView(QWidget):
    def __init__(self, parent_layout):
    super().__init__()

    self.parent_layout = parent_layout
    self.plotWidget = pg.PlotWidget()
    self.plotWidget.setMinimumHeight(300)
    self.plotWidget.setMinimumWidth(450)

    self.parent_layout.addWidget(self.plotWidget)
    self.setLayout(self.parent_layout)

    # Sample data
    x = np.array([1,2,3,4,5,6,7,8,9,10])
    y = np.array([5,4,6,4,3,5,6,6,7,8])

    # Use the clean constructor: x, y
    self.scatter = pg.ScatterPlotItem(x, y, pen=pg.mkPen((255, 45, 33)), size=10)
    self.plotWidget.addItem(self.scatter)

    # Set plot ranges
    self.plotWidget.setXRange(min(x), max(x))
    self.plotWidget.setYRange(min(y), max(y))


    See the image link to understand what I see on the graph.

    image of scatterplt data stuck on top left side in graph

    Continue reading...

Compartilhe esta Página