Skip to content

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

Closed

Description

@inxp

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

Activity

  1. changed the title [-]Zoom rubber band lags in larger window[Bug]: [/-] [+][Bug]: Zoom rubber band lags in larger window[/+] on Sep 20, 2022
  2. QuLogic commented on Sep 20, 2022

    @QuLogic
    Member

    How large is large enough to be slow?

  3. inxp commented on Sep 21, 2022

    @inxp
    Author

    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_())
    
    
    
  4. inxp commented on Dec 11, 2022

    @inxp
    Author

    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?

  5. jklymak commented on Dec 11, 2022

    @jklymak
    Member

    @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?

  6. added this to the v3.6.3 milestone on Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions