[Python] Axis labels clipping or cut off in pyqtgraph PlotWidget

Discussão em 'Python' iniciado por Stack, Maio 30, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to make a QWidget wrapper class which has a pyqtgraph.PlotWidget within it to plot my data. But when I add labels into my graph, it somehow gets cut off or clipped at the edge of the widget as seen in the picture.

    I've tried numerous methods to solve it, including:

    • Introducing margins to my container class
    • QSizePolicy
    • Adding padding

    But all do not solve the underlying issue. From what I understand, All these labels are part of a PlotItem (GraphicsView): https://pyqtgraph.readthedocs.io/en/latest/getting_started/plotting.html. But I couldn't figure out how to scale it properly so the labels do not clip. And no, I do not have QtDesigner...

    Here's my code:

    from PyQt6.QtWidgets import QWidget, QVBoxLayout
    import pyqtgraph as pg

    class LivePlot(QWidget):
    def __init__(self):
    super().__init__()
    layout = QVBoxLayout()
    self.setLayout(layout)
    self.plot_graph = pg.PlotWidget()
    self.plot_graph.setTitle("Picoscope signal")
    self.plot_graph.setLabel("left", "ADC Counts")
    self.plot_graph.setLabel("bottom", "Delay (mm)")

    layout.addWidget(self.plot_graph)


    Example of graph, note the xlabel being cut off

    Continue reading...

Compartilhe esta Página