FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Matplotlib 2 is extremely slow after `plt.show()` · Issue #8129 · matplotlib/matplotlib · GitHub

Repository navigation

Matplotlib 2 is extremely slow after plt.show() #8129

Closed as not planned
Closed as not planned

Description

I recently upgraded to matplotlib 2.0.0 and it has this weird behavior in the interactive window where after I do a plt.show and close the interactive window, it hangs and I can't type anything. I can only type if I press control+c, but even so it takes about 15 seconds before the KeyboardInterrupt sets in and then I can type.

The behavior can be reproduced simple with this code

from matplotlib import pyplot as plt
plt.plot(range(10))
plt.show()

Apparently this only happens with IPython, since I tried in a simple python session and there was no problem. But I think it's not IPython-related because this never happened with any of the previous Matplotlib versions, just version 2. So I thought I'd post this here instead on the IPython issues.

Matplotlib version 2.0.0
Python version 2.7.12
IPython version 2.4.1
Linux Mint 18.1
get_backend() output: 'TkAgg'

Activity

  1. efiring commented on Feb 22, 2017

    Member

    What operating system, and what matplotlib backend?

    That's a very old IPython version; can you try with a recent version?

  2. WeatherGod commented on Feb 22, 2017

    Member
  3. tomchor commented on Feb 22, 2017

    Author

    Sorry, I forgot that information. Just updated the issue.

    EDIT:

    Just installed IPython 5.2.2 and the issue completely went away. I never noticed my IPython version was slow, so I never bothered to update it.

    Apparently matplotlib doesn't work well with old versions of IPython. Although I never read that anywhere. Maybe there should be some note about that somewhere.

    Thanks

  4. tacaswell commented on Feb 23, 2017

    Member

    It smells like Tk is not giving up control of the process?

    I can confirm that closing the window does not exit (conda has old enough versions of everything!). This is specific to Tk (qt4 works as expected).

    12:18 $ ipython                                                                                                                                                                                                    
    WARNING: Readline services not available or not loaded.                                                                                                                                                            
    WARNING: The auto-indent feature requires the readline library                                                                                                                                                     
    Python 2.7.13 |Continuum Analytics, Inc.| (default, Dec 20 2016, 23:09:15)                                                                                                                                         
    Type "copyright", "credits" or "license" for more information.                                                                                                                                                     
                                                                                                                                                                                                                       
    IPython 2.4.1 -- An enhanced Interactive Python.                                                                                                                                                                   
    Anaconda is brought to you by Continuum Analytics.                                                                                                                                                                 
    Please check out: http://continuum.io/thanks and https://binstar.org                                                                                                                                               
    ?         -> Introduction and overview of IPython's features.                                                                                                                                                      
    %quickref -> Quick reference.                                                                                                                                                                                      
    help      -> Python's own help system.                                                                                                                                                                             
    object?   -> Details about 'object', use 'object??' for extra details.                                                                                                                                             
                                                                                                                                                                                                                       
    In [1]: import matplotlib                                                                                                                                                                                          
                                                                                                                                                                                                                       
    In [2]: matplotlib.use('tkagg')                                                                                                                                                                                    
                                                                                                                                                                                                                       
    In [3]: import matplotlib.pyplot as plt                                                                                                                                                                            
                                                                                                                                                                                                                       
    In [4]: plt.plot(range(5))                                                                                                                                                                                         
    Out[4]: [<matplotlib.lines.Line2D at 0x7fd48611b290>]                                                                                                                                                              
                                                                                                                                                                                                                       
    In [5]: plt.show()                                                                                                                                                                                                 
    ^C---------------------------------------------------------------------------                                                                                                                                      
    KeyboardInterrupt                         Traceback (most recent call last)                                                                                                                                        
    <ipython-input-5-c4e69632d98a> in <module>()                                                                                                                                                                       
    ----> 1 plt.show()                                                                                                                                                                                                 
                                                                                                                                                                                                                       
    /tmp/old_stuff/lib/python2.7/site-packages/matplotlib/pyplot.pyc in show(*args, **kw)                                                                                                                              
        251     """                                                                                                                                                                                                    
        252     global _show                                                                                                                                                                                           
    --> 253     return _show(*args, **kw)                                                                                                                                                                              
        254                                                                                                                                                                                                            
        255                                                                                                                                                                                                            
                                                                                                                                                                                                                       
    /tmp/old_stuff/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in __call__(self, block)                                                                                                                   
        191                                                                                                                                                                                                            
        192         if not is_interactive() or get_backend() == 'WebAgg':                                                                                                                                              
    --> 193             self.mainloop()                                                                                                                                                                                
        194                                                                                                                                                                                                            
        195     def mainloop(self):                                                                                                                                                                                    
                                                                                                                                                                                                                       
    /tmp/old_stuff/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.pyc in mainloop(self)                                                                                                                 
         69 class Show(ShowBase):                                                                                                                                                                                      
         70     def mainloop(self):                                                                                                                                                                                    
    ---> 71         Tk.mainloop()                                                                                                                                                                                      
         72                                                                                                                                                                                                            
         73 show = Show()                                                                                                                                                                                              
                                                                                                                                                                                                                       
    /tmp/old_stuff/lib/python2.7/lib-tk/Tkinter.pyc in mainloop(n)                                                                                                                                                     
        417 def mainloop(n=0):                                                                                                                                                                                         
        418     """Run the main loop of Tcl."""                                                                                                                                                                        
    --> 419     _default_root.tk.mainloop(n)                                                                                                                                                                           
        420                                                                                                                                                                                                            
        421 getint = int                                                                                                                                                                                               
                                                                                                                                                                                                                       
    KeyboardInterrupt:                                                                                                                                                                                                 
                                                                                                                                                                                                                       
    In [6]:                                                                                                                                                                                                            
                    
    
  5. malfatti commented on Apr 20, 2017

    I'm having this issue too with Tkagg. After plt.show(), figure shows, but then closing the window hangs the console forever. But I also had this issue with matplotlib 1.5.3.

    OS: Gentoo Linux amd64
    Python: 3.{5,6}
    IPython: 5.3.0

  6. tacaswell commented on Apr 20, 2017

    Member

    att @Carreau I suspect that there may be some input hook issues with tk....

  7. added this to the milestone on Apr 20, 2017
  8. malfatti commented on Apr 20, 2017

    I don't know if it helps, but this issue is not on matplotlib 1.5.1.

  9. tacaswell commented on Apr 20, 2017

    Member

    That makes it more likely to be a bug in the IPython tk inputhook. One of the changes is 1.5.3 is to automatically enable that if Matplotlib detects it has been imported inside of a IPython sessions (but 1.5.1 did not).

  10. Carreau commented on Apr 20, 2017

    Contributor

    One of the possibility is to test with IPython 6 (released yesterday, Python 3 only) anduse https://github.com/ipython/rlipython as it we re-us readline and should skip the PTK eventloop. It should be backported to 5.4 but this has not been released yet.

    I'm unfamiliar with Tk hooks, I'll see if I find time and manage to reproduce

  11. modified the milestones: , on Sep 24, 2017
  12. modified the milestones: , on Oct 9, 2017
  13. malfatti commented on Dec 5, 2017

    Hello!

    I still have this issue in 2.1.0-r1. I tried with IPython 6 and rlipython as suggested, but still the terminal hangs after closing the figure. Is there any possible workaround (so I don't stay trapped in 1.5.1 :) )?

    Thanks :D

  14. tacaswell commented on Dec 5, 2017

    Member

    The issues #9077 #9856 #8845 may be related

    The PRs
    #9275 #9356 might help.

    There is something funny going on with tk tear-down and probably requires someone who understands Tk to spend some time tracing exactly what is going on.

  15. homerobse commented on Feb 17, 2023

    I'm having a similar problem in which matplotlib is slow after plt.show(). It takes about 10s before it opens the window. I'm on Ubuntu WSL on Windows 11. The lag only happens in the first time I plot something. Second time is fast.

    These are my versions.
    matplotlib 3.7.0 py311h38be061_0 conda-forge
    matplotlib-base 3.7.0 py311h8597a09_0 conda-forge
    matplotlib-inline 0.1.6 pyhd8ed1ab_0 conda-forge

    Any idea about how to solve this problem or where/what to search?

  16. homerobse commented on Feb 17, 2023

    This lag happens in both my base conda environment and a custom one. But when I log in from a different Windows user and try to do the same, there is no lag regardless of what conda environment I use. Maybe this is something in the Ubuntu WSL environment and how it communicates with the X Server? If it is, how can I solve it?

  17. github-actions commented on Feb 19, 2024

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  18. jklymak commented on Feb 19, 2024

    Member

    I'll close this. If someone has a modern slowness issue please open a new report.

  19. added
    status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.
    and removed
    status: inactiveMarked by the “Stale” Github Action
    on Feb 19, 2024
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

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL