Skip to content

plt.plot(...) makes python repl in cmd slow #5159

Closed

Description

@jankatins

When producing a small plot in the console, the console becomes very sluggish afterwards:

λ python
Python 2.7.10 |Continuum Analytics, Inc.| (default, Sep 15 2015, 14:26:14) [MSC v.1500 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import matplotlib.pyplot as plt
>>> plt.plot([1,2,3], marker="o")
[<matplotlib.lines.Line2D object at 0x0000000008DB60B8>]

# from here on it's sluggish until I exit -> typing shows the next character
# with a noteable delay and c&p is kind of "typing" the text instead of 
# almost instantly there

>>> plt.show()

This a clean new conda env py2.7 (conda create -n mew_test python matplotlib seaborn ipython) on windows7, 64bit. I also have cmder installed, but it also happens in the default cmd console

Activity

  1. WeatherGod commented on Sep 30, 2015

    @WeatherGod
    Member

    Which version of matplotlib and which backend (I don't know what the
    defaults are for Windows from anaconda).

    On Wed, Sep 30, 2015 at 10:00 AM, Jan Schulz notifications@github.com
    wrote:

    When producing a small plot in the console, the console becomes very
    sluggish afterwards:

    λ python
    Python 2.7.10 |Continuum Analytics, Inc.| (default, Sep 15 2015, 14:26:14) [MSC v.1500 64 bit (AMD64)] on win32

    Type "help", "copyright", "credits" or "license" for more information.
    Anaconda is brought to you by Continuum Analytics.
    Please check out: http://continuum.io/thanks and https://anaconda.org

    import matplotlib.pyplot as plt
    plt.plot([1,2,3], marker="o")
    [<matplotlib.lines.Line2D object at 0x0000000008DB60B8>]
    [ from here on it's sluggish until I exit -> typing shows the next character with a noteable delay and c&p is kind of "typing" the text instead of almost instantly there]
    plt.show()

    This a clean new conda env py2.7 (conda create -n mew_test python
    matplotlib seaborn ipython) on windows7, 64bit. I also have cmder
    installed, but it also happens in the default cmd console

    —
    Reply to this email directly or view it on GitHub
    #5159.

  2. jankatins commented on Sep 30, 2015

    @jankatins
    ContributorAuthor
    >>> matplotlib.__version__
    '1.4.3'
    >>> matplotlib.get_backend()
    u'Qt4Agg'
    
  3. jankatins commented on Sep 30, 2015

    @jankatins
    ContributorAuthor

    Using Agg as a backend does not have this problem (no sluggish typing after plt.plot()), but on the other hand I also do not get a plot shown after plt.show() . Not sure how to get a plot window with that backend?

    import matplotlib
    matplotlib.use('Agg')
    import matplotlib.pyplot as plt 
    plt.plot([1,2,3])
    #not sluggish afterwards :-)
    plt.show() # does not bring up the plotting window :-(
    

    (It seems that I never really learned how to use matplotlib in another environement than the ipython notebook...)

  4. tacaswell commented on Sep 30, 2015

    @tacaswell
    Member

    Do you have the same issue from just importing pyqt? iirc, there are some issues with the os inputhook + windows.

    Do you have the same issue if you use ipython and do a

    %matplotlib qt
    

    ?

  5. jankatins commented on Oct 1, 2015

    @jankatins
    ContributorAuthor

    I've run from PyQt4 import QtGui and didn't notice a slowdown afterwards. Running %matplotlib qt in an ipython console (not qt, not notebook!) also didn't change anything.

  6. WeatherGod commented on Oct 1, 2015

    @WeatherGod
    Member

    when you say "also didn't change anything", do you mean that it is slow
    just like at the repl, or that it is normal speed, just like using Qt4
    normally?

    On Thu, Oct 1, 2015 at 6:08 AM, Jan Schulz notifications@github.com wrote:

    I've run from PyQt4 import QtGui and didn't notice a slowdown afterwards.
    Running %matplotlib qt in an ipython console (not qt, not notebook!) also
    didn't change anything.

    —
    Reply to this email directly or view it on GitHub
    #5159 (comment)
    .

  7. jankatins commented on Oct 1, 2015

    @jankatins
    ContributorAuthor

    It's normal, e.g. typing is shown instantly and c&p as well.

  8. tacaswell commented on Oct 1, 2015

    @tacaswell
    Member

    I would just use the IPython shell then 😉. It takes care of many of the annoying details about setting up interactive mode and managing the gui event loop.

    I can't reproduce this on a linux box.

  9. jankatins commented on Oct 1, 2015

    @jankatins
    ContributorAuthor

    It happens in both python and ipython. Unfortunately I currently don't have access to a different windows box, to test if it's specific to my box or to windows. :-(

  10. efiring commented on Oct 1, 2015

    @efiring
    Member

    Is the tkagg backend available? E.g. in ipython, %matplotlib tk.
    I suspect your problem with qt involves a library conflict with something else installed on your machine. If it were a universal problem with Anaconda python 2.7 on Windows, I think Continuum would have been deluged with complaints by now, and I don't think I have seen this one on the anaconda mailing list.

  11. Tillsten commented on Oct 2, 2015

    @Tillsten
    Contributor

    Can confirm the behavior with qt, but i think this a really old bug, which never got fixed. Something with way readline is used.

  12. Tillsten commented on Oct 2, 2015

    @Tillsten
    Contributor

    I also remember that using ipython would we the fix, but this is not the case. Note that figure doesent have to be show, the slowdown happens after calling plot.

    Using %gui qt in ipython before seems to be fixing the issue.

  13. tacaswell commented on Oct 2, 2015

    @tacaswell
    Member

    Is this an old mpl bug or an old pyqt bug?

    Does this happen on master branch/with the rc (which has a windows conda
    build on the conda-forge channel).

    On Fri, Oct 2, 2015, 10:05 Till Stensitzki notifications@github.com wrote:

    I also remember that using ipython would we the fix, but this is not the
    case. Note that figure doesent have to be show, the slowdown happens after
    calling plot.

    —
    Reply to this email directly or view it on GitHub
    #5159 (comment)
    .

  14. Tillsten commented on Oct 2, 2015

    @Tillsten
    Contributor

    The mpl policies was always that if you want have interactive plots in the repl working without any haggle one has to use ipython. This is still true, as long either %gui or %matplotlib is called. As long all the input-hook experience is in the ipython team it is properly the best way, even if having the code directly in mpl would be also nice.

  15. jankatins commented on Oct 4, 2015

    @jankatins
    ContributorAuthor

    Ok, I tested it with %matplotlib tk and it doesn't become sluggish. I will create a new test env for the newer matplotlib version and then see what happens there...

  16. 2 remaining items

  17. jankatins commented on Oct 4, 2015

    @jankatins
    ContributorAuthor

    Another observation:

    • before plt.plot(), I can paste long lines (2k words of lorem ipsum), but the python interpreter goes to 100% CPU (on one core) and it takes a while to paste the complete line (but not as slow as with plot)...
    • after plt.plot(), I can't paste long lines anymore: the interpreter has no CPU, but only 4 chars are shown (=hang?). I have to kill the interpreter (via proc explorer) to get the rest of the chars displayed (in cmd!). Shorter texts can be pasted (I tried with 230 chars), it's much slower as without the plot call but the interpreter (and cmd/...) does not use much CPU (~1% of one core).
  18. Tillsten commented on Oct 4, 2015

    @Tillsten
    Contributor

    You need to use Ipython and call %matplotlib your_backend to get non sluggish behaviour. Else the eventloop and pythons inputhook won't play nice with each other.

  19. jankatins commented on Oct 4, 2015

    @jankatins
    ContributorAuthor

    Using %gui qt in ipython before the plt.plot() prevents the sluggishness (=c&p is fast afterwards). Even calling this after plt.plot() (and observing sluggish behaviour) is restoring the fast c&p behaviour.

    So what this means is that using matplotlib in interactive mode on windows will result in sluggish behaviour unless setting the backend to something else than qt4 or using ipython and %gui qt?

  20. Tillsten commented on Oct 4, 2015

    @Tillsten
    Contributor

    Yeah, but please note that it is not maplotlibs fault, try:

    from PyQt4 import QtGui
    app = QtGui.QApplication([])
    

    and you will see the same behaviour. IPython jumps through some hoops to circumvent that. Note that QtCore.pyqtRemoveInputHook() fixes the sluggishness, but i don't know the downsides of it.

  21. jankatins commented on Oct 4, 2015

    @jankatins
    ContributorAuthor

    With your code snippets I found ipython/ipython#481, ipython/ipython#815 and ipython/ipython#2294 which seem to implement the workarounds which make this work...

    Not sure if there is any actionable item here, if matplotlib doesn't want to implement the same workaround as IPython. I think the only thing which makes sense is a warning ala "Use ipython and %gui qt" on import if _onwindows and backend=="QT4Agg" and ("ipython inputhook not present" or "not in ipython")...

    Or simple hope that noone uses matplotlib in REPL mode on windows without enough knowledge to use %gui qt :-)

  22. Tillsten commented on Oct 4, 2015

    @Tillsten
    Contributor

    I personally would be fine with calling QtCore.pyqtRemoveInputHook() and emitting a warning that the inputhook has been removed. Of course only under windows if the problem is only there. Maybe someone should ask on the pyqt4 mailing list if the behavior is known.

  23. tacaswell commented on Oct 4, 2015

    @tacaswell
    Member

    The downside of removing the inputhook is that figures will no longer be 'live' unless you explicitly start the event loop (ex via plt.pause()).

  24. jorisvandenbossche commented on Oct 5, 2015

    @jorisvandenbossche

    FWIW, I also experienced this behaviour for some time on Windows with IPython (also using conda). Normally I use %matplotlib to enable interactivity, but when I forget to type that and already do a plot, the terminal indeed becomes unusable slow

  25. tomderuijter commented on Nov 17, 2015

    @tomderuijter

    I can also confirm this issue. Using Anaconda 2.3.0 with matplotlib 1.4.3 and Python 3.4.3.

  26. added this to the milestone on Nov 17, 2015
  27. nplanel commented on Aug 18, 2016

    @nplanel

    same issue on a fresh Ubuntu 14.04 LTS server uptodate and in an virtualenv (may not related)
    Installed via pip

    note : the host is a VM I can share you a snapshot
    note2: the issue is seems to be related to X11/freetype as the VM is accessed via a slow ssh connection and an X11 tunnel (ssh -X) as matplotlib/backends/backend_gtk.py need to open an X11 DISPLAY
    So may there are a font resolution inserted in the REPL by matplotlib.

    To reproduce it :

    sudo apt-get update
    sudo apt-get install python-pip python-dev python-virtualenv
    virtualenv --system-site-packages ~/myenv
    pip install matplotlib
    python2
    import numpy             as np
    import matplotlib.pyplot as plt
    ... the REPL is very slow now
    

    Workaround, choosing your backend (not choosing gtk) fix the issue

    import matplotlib
    matplotlib.use('Agg')
    import matplotlib.pyplot as plt
    
  28. efiring commented on May 23, 2019

    @efiring
    Member

    Closing, but if the problem is still occurring please reopen.

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

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions