8000 Poor UI responsiveness of 3.3.1 compared with 3.2.2 for interactive mode UI using widgets · Issue #18324 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Poor UI responsiveness of 3.3.1 compared with 3.2.2 for interactive mode UI using widgets #18324
Closed
@zuzzy

Description

@zuzzy

Performance Issue - poor UI responsiveness of 3.3.1 compared with 3.2.2 for interactive mode UI using widgets

Since 3.3.1 the responsiveness of a Matplotlib based program I have been developing has got a lot more sluggish.

This is a application that runs in interactive mode with a UI built out of about 40 widgets.

This can be seen when there is a mouse move operation, or other event, eg button push. There can be a long delay.

This is reproduced in the code below. The maximum execution time of fig.canvas.flush_events() being much longer
in 3.3.1 that it was in 3.2.2 and this length of time determines the feel and responsiveness in interactive mode. In this example the maximum call time has increased from 0.32s to 9.12s making the UI feel very unresponsive.

Would be grateful for any insights on how responsiveness may be restored in 3.3.1 onwards.

Code for reproduction

####################################################################
75FC
#############
# Run the following code first with 3.2.2 and then with 3.3.1
# to observe difference off responsiveness in button press
# and highlighting on a widget based UI between 3.2.2 to 3.3.1
# Stop the program by clicking the x to close the main window and observe
# maximum flush execution times reported.
#
# The increased lag is seen on mouse moves and widget operation.
# 3.3.1 is very slow compared with 3.2.2
# maximum times are somewhat related to the number of widgets,
# but there is a large difference in maximum flush times between 3.2.2 and 3.3.1
# In this example 0.32s increases to 9.12s which makes the interactive display almost unusable.
# Peter Matthewson 22Aug20
##################################################################################

import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.widgets import  Button
import time

#something to connect the buttons to
def bfunc(self):
    print("button press")

mpl.use("Qt5Agg") # Also tried that behaviour is similar with TkAgg
plt.ion() #its an issue seen in interactive mode
plt.show()

#main axes
fig, ax = plt.subplots(figsize=(15, 7),)

NBUTTONS=50 #add widgets
a=[]
b=[]
for i in range( NBUTTONS):
    axsave = plt.axes([0.2+i//10*0.07, 0.7-0.05*(i%10), 0.06, 0.035]) # use the plt interface
    Bsave = Button(axsave, 'button '+str(i))
    Bsave.on_clicked(bfunc)
    a.append(axsave)
    b.append(Bsave)

# detect close event on main window
Running=True # to notify end
def handle_close(evt):
    global Running
    print("stopping - handle close...")
    Running=False
fig.canvas.mpl_connect('close_event', handle_close)

# background loop
calls=0
tmax=0.0
while Running:
    if not calls%100000:
        print("calls =", calls) # update on the number of calls from background loop
    calls+=1
    ts=time.time()
    fig.canvas.flush_events()   # update the plot and take care of window events (like resizing etc.)
    t=time.time()-ts
    tmax=max(t,tmax)
# summary
print("Matplotlib version:", mpl.__version__)
print("max flush_events time = ",tmax)

Actual outcome
image

Output from Execution with Matplotlib 3.3.1
"D:\PM Python\Py38_64\Scripts\python.exe" "D:/PM Python/BassIntonation/Mpl33_investigation.py"
calls = 0
calls = 100000
calls = 200000
calls = 300000
calls = 400000
calls = 500000
stopping - handle close...
Matplotlib version: 3.3.1
max flush_events time =  9.19574522972107

Output from Execution with Matpltlib 3.2.2
"D:\PM Python\Py38_64\Scripts\python.exe" "D:/PM Python/BassIntonation/Mpl33_investigation.py"
calls = 0
calls = 100000
calls = 200000
calls = 300000
calls = 400000
calls = 500000
calls = 600000
calls = 700000
calls = 800000
calls = 900000
stopping - handle close...
Matplotlib version: 3.2.2
max flush_events time =  0.3191030025482178

Config:
  * Windows 10, Dell Laptop i7
  * Matplotlib version: 3.2.2 and 3.3.1 comparison
  * TkAgg and Tt5Agg behave similarly
  * Python version: 3.8 64 bit
  * Pycharm

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0