0

I´m currently developing a software to process spectroscopic data using python. I´m using PyQt6 to design the gui and matplotlib to plot the data. To simplify the data selection I added a cursor widget from matplotlib to the axes. For improved performace I used the blitting mode.

Here´s a minimal code example:

# Import packages
from PyQt6.QtWidgets import QMainWindow, QApplication, QWidget, QVBoxLayout
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.widgets import Cursor
from matplotlib.figure import Figure
import numpy as np


# Main window
class MainWindow(QMainWindow):
    def __init__(self):
        # Initialize QMainWindow
        super().__init__()
        # Get MplWidget
        self.mpl_widget = MplWidget()
        # Set MplWidget as central widget
        self.setCentralWidget(self.mpl_widget)
        # Create axes
        self.ax = self.mpl_widget.canvas.figure.add_subplot(111)
        # Reference Cursor
        self.cursor = Cursor(self.ax, useblit=True)
        # Plot some random stuff
        x, y = np.random.rand(100), np.random.rand(100)
        self.ax.scatter(x, y)
        # Show app
        self.show()


# MplCanvas
class MplWidget(QWidget):
    def __init__(self, parent=None):
        # Initialize QWidget
        super().__init__(parent)
        # Create canvas
        self.canvas = FigureCanvas(Figure())
        # Set constrained layout
        self.canvas.figure.set_constrained_layout(True)
        # Create layout
        layout = QVBoxLayout()
        # Add canvas
        layout.addWidget(self.canvas)
        # Set layout
        self.setLayout(layout)


# Initialize app
app = QApplication([])
UI = MainWindow()
app.exec()

Generally everything works fine, the cursor appears when hovering the axis and dissapears when leaving it, but when the mouse enters the axis, the whole axis content moves a little bit. Sometimes the figure edges also change their colors, e.g. from black to gray.

Here are two gifs to explain the phenomenon:

Minimal example

Real application

Does anyone know how to solve this problem?

2
  • i did a quick check with pyqt5 since I don't have qt6 installed at the moment (just changed first input to from PyQt5.) and I don't get the issues you're describing... maybe its related to qt6? Commented Jan 20, 2023 at 15:34
  • I think so too. The problem only appears in PyQt6, not in PyQt5. Commented Jan 20, 2023 at 22:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.