Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Bug]: Zoom rubber band lags in larger window #23968

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
inxp opened this issue Sep 20, 2022 · 4 comments · Fixed by #24692
Closed

[Bug]: Zoom rubber band lags in larger window #23968

inxp opened this issue Sep 20, 2022 · 4 comments · Fixed by #24692
Milestone

Comments

@inxp
Copy link

inxp commented Sep 20, 2022

Bug summary

Zoom rubber band is smooth in small window. But when I increase the size of the window the performance degrades.

Here I have stretched the window across two monitors for illustration.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

# Data for plotting
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)

fig, ax = plt.subplots()
ax.plot(t, s)

ax.set(xlabel='time (s)', ylabel='voltage (mV)',
       title='About as simple as it gets, folks')
ax.grid()

fig.savefig("test.png")
plt.show()

Actual outcome

2022-09-20_17-23-16

Expected outcome

2022-09-20_17-21-24

Additional information

No response

Operating system

Windows

Matplotlib Version

3.6

Matplotlib Backend

QtAgg

Python version

3.8.10

Jupyter version

No response

Installation

pip

@inxp inxp changed the title Zoom rubber band lags in larger window[Bug]: [Bug]: Zoom rubber band lags in larger window Sep 20, 2022
@QuLogic
Copy link
Member

QuLogic commented Sep 20, 2022

How large is large enough to be slow?

@inxp
Copy link
Author

inxp commented Sep 21, 2022

The GIF that I posted is a window stretched over two 24" monitors, each having 1920x1080 resolution.

For me, the lag becomes noticeable in a 1920x1080 window.

Note that the same lag does not exist or is very low in the matplotlib 2.2.5 version with the Qt5Agg backend.

There is no lag in TkAgg backend for any window size.

Please try comparing the performance of rubber band in the following code between Matplotlib version 2.2.5 and 3.6.0.



import sys
from PyQt5.QtWidgets import QWidget, QApplication, QPushButton, QVBoxLayout

from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
import matplotlib.pyplot as plt

import random

class Window(QWidget):
    def __init__(self, parent=None):
        super(Window, self).__init__(parent)

        self.figure = plt.figure()
        
        data = [random.random() for i in range(10)]

        ax = self.figure.add_subplot(111)

        ax.plot(data, '*-')

        self.canvas = FigureCanvas(self.figure)

        self.toolbar = NavigationToolbar(self.canvas, self)
        
        self.canvas.draw()

        layout = QVBoxLayout()
        layout.addWidget(self.toolbar)
        layout.addWidget(self.canvas)
        self.setLayout(layout)

    
if __name__ == '__main__':
    app = QApplication(sys.argv)

    main = Window()
    main.showMaximized()

    sys.exit(app.exec_())


@inxp
Copy link
Author

inxp commented Dec 11, 2022

Update

On further testing, I found that lag is there even when dragging legends.

So I checked paintEvent function in FigureCanvasQTAgg of \backends\backend_qtagg.py

The delay was mainly due to following statement in _unmultipled_rgba8888_to_premultiplied_argb32 function of cbook\__init__.py

argb32 = np.take(rgba8888, [2, 1, 0, 3], axis=2)

_unmultipled_rgba8888_to_premultiplied_argb32 function is called by paintEvent function

The function call was added as part of #11845 commit.

On reverting the changes done in commits #11731 and #11845, The lag was gone. Everything is working as expected.

So I think, as window size increases it takes more time for np.take statement causing delay between subsequent paints.

Am I doing something wrong?

@jklymak
Copy link
Member

jklymak commented Dec 11, 2022

@anntzer you introduced _unmultiplied_rgba8888_to_premultiplied_argb32 in #11845, and the original issue says maybe it was an issue with qt5.1 and earlier. Given that qt5.2 is now 9 years old do we need to support 5.1 any longer and maybe this function isn't required?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants