Skip to content

after plotting using Qt4Agg backend in Mac OS, terminal gets slow, CPU increases #6038

Closed

Description

@js54434

Frequently, when I make plots in matplotlib using the Qt4Agg backend in the python shell in a default Mac OS terminal window, the CPU percentage gets high (as seen by Activity Monitor) and the terminal becomes laggy as I'm typing into it. The problem doesn't always occur (I can reproduce it maybe 50% of the time), but I've seen it after simply entering the following into the python shell

import matplotlib.pyplot as plt
plt.figure()

and then, say, holding down "a" on the keyboard and seeing if the CPU jumps up to 30% or so. Generally, the problem seems to start only after I've created the first figure with plt.figure() (after importing matplotlib.pyplot as plt). (The plot isn't displayed in this case, but I've also had the problem in interactive mode after the plot is displayed.) The lagginess continues after the figure's closed and seems to get worse over time, basically making it difficult to continue until I restart the python shell. The CPU gets high (say, 30-120% rather than the usual 0-2%), but only when I'm typing or when it's processing the last thing I typed.

I do not have the problem with the TkAgg backend, though for the macosx backend I do have the different issue shown here: #5964. backend.qt4 was set to PyQt4 in the matplotlibrc file.

matplotlib version: 1.5.1
python 3.5.1, Anaconda 2.5.0 (x86_64)
(I just reinstalled Anaconda with python 3.5, but I've also had the issue with a previous Anaconda version for python 2.7.)
Mac OS X 10.11.3

Activity

  1. efiring commented on Feb 21, 2016

    @efiring
    Member

    This is with the plain python shell? If so, does it also occur with the ipython shell?

  2. js54434 commented on Feb 21, 2016

    @js54434
    Author

    I've just checked, and yes, it does happen with ipython.

  3. tacaswell commented on Feb 21, 2016

    @tacaswell
    Member

    I wonder if it is related to readline being installed or not? The integration of the repl with an GUI event loop can be complex.

  4. efiring commented on Feb 22, 2016

    @efiring
    Member

    I can reproduce the high CPU usage (15-30%) while holding down a key, after plt.figure(), and with qt4agg but not with tkagg. This is on Mavericks, in ipython.
    It does not occur with %matplotlib, so the figure is displayed, however.
    It does occur if I leave out the magic and use plt.ion() to display the figure.
    Closing the figure doesn't help; the cpu usage remains high when holding a key down.

    And now I am baffled, because when I try to reproduce the phenomenon in ipython, it is not happening.
    Then I switch to the plain python console, and the CPU usage can go as high as 50%.
    And there also, it doesn't always happen.

    I wonder whether this is related to the rather long delay (many seconds, unless I get impatient and hit control-C) I sometimes encounter when exiting ipython after plotting.

  5. tacaswell commented on Feb 22, 2016

    @tacaswell
    Member

    IPython does the event loop integration differently that pyqt4 does 'stock' (and that handling is installed via %matplotlib).

    Can you reproduce this if you just make a qapp and create a window?

  6. timhoffm commented on Jul 14, 2020

    @timhoffm
    Member

    Closing due to lack of response. Note that Qt4 was deprecated with Matplotlib 3.3.

    Feel free to reopen if there is still an issue with Qt5.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions