Slow REPL after PyPlot

I was using the REPL with 0.6.2 on MacOS, and noticed that if I create a plot with PyPlot, the REPL slows to a complete crawl, becoming unusable. This is after simple commands like:

using PyPlot
x = linspace(0,10)|>collect;
y = sin.(x);
plot(x,y)

I do not have the same issue with either Plots or PlotlyJS

I couldn’t reproduce this behaviour in REPL with 0.6.2 on my mac. Maybe a little more information will be helpful?

Not sure what more info I could provide. This is MacOS Sierra. I installed form the .dmg, and to the best of my knowledge the installation is pretty vanilla. Is there a way of getting the kind of diagnostic information you think would be useful?

What are PyPlot.backend, PyPlot.version, PyPlot.PyCall.pyversion, and PyPlot.PyCall.python?

I’ve encountered this over the past week on Julia 0.6.1 and 0.6.2 on an up-to-date Arch Linux.
After plotting with PyPlot, I have a constant CPU usage and both the plot GUI and the REPL become very slow to respond.
I find if I enter 1+1 into the REPL then hit CTRL+C just before it has a chance to output 2, I interrupt something:

ERROR (unhandled task failure): InterruptException:
Stacktrace:
 [1] #_pycall#67(::Array{Any,1}, ::Function, ::PyCall.PyObject, ::PyCall.PyObject, ::Vararg{PyCall.PyObject,N} where N) at /home/peter/.julia/v0.6/PyCall/src/PyCall.jl:663
 [2] _pycall(::PyCall.PyObject, ::PyCall.PyObject, ::Vararg{PyCall.PyObject,N} where N) at /home/peter/.julia/v0.6/PyCall/src/PyCall.jl:641
 [3] #pycall#70(::Array{Any,1}, ::Function, ::PyCall.PyObject, ::Type{PyCall.PyObject}, ::PyCall.PyObject, ::Vararg{PyCall.PyObject,N} where N) at /home/peter/.julia/v0.6/PyCall/src/PyCall.jl:672
 [4] (::PyCall.##3#4{PyCall.PyObject,PyCall.PyObject,PyCall.PyObject,PyCall.PyObject})(::Timer) at /home/peter/.julia/v0.6/PyCall/src/gui.jl:149
 [5] (::Base.##300#301{PyCall.##3#4{PyCall.PyObject,PyCall.PyObject,PyCall.PyObject,PyCall.PyObject},Timer})() at ./event.jl:436

Afterward, the REPL is responsive again, but PyPlot no longer works (the figure window appears, but the GUI and the plot itself does not).

In my case:

PyPlot.backend = "qt5agg"
PyPlot.version = v"2.1.1"
PyPlot.PyCall.pyversion = v"3.6.3"
PyPlot.PyCall.python = "python"

This issue persists after running

ENV["PYTHON"] = ""
Pkg.build("PyCall")

in which case I have

PyPlot.PyCall.pyversion = v"2.7.14"
PyPlot.PyCall.python = "/home/peter/.julia/v0.6/Conda/deps/usr/bin/python"

I use fedora which has both python2 and python3, and I tried to use PyPlot in Julia and everytime it gets super slow, so I just uninstall PyPlot and stick with Gadfly.

I also noticed this on matplotlib 2.1.1 (not earlier), when I use “qt5agg.” Switching to “tkagg” solved this problem. (Applies to Julia 0.6.1 and 0.6.2 on Win 10 64.) /Paul S

Every 50 milliseconds, with q5agg, it has to call back to Qt to flush Qt’s event-handling queue. I wonder if this has become crazy slow in recent Qt versions?

julia> PyPlot.backend
"Qt5Agg"

julia> PyPlot.version
v"2.1.1"

julia> PyPlot.PyCall.pyversion
v"3.6.3"

julia> PyPlot.PyCall.python
"/Users/gideonsimpson/anaconda3/bin/python"

Same effect observed with Qt4Agg backend so this is likely an issue with matplotlib’s use of qt rather than a qt issue.

Still, I don’t have this issue with

julia> PyPlot.backend
"Qt5Agg"

julia> PyPlot.version
v"2.0.2"

julia> PyPlot.PyCall.pyversion
v"3.6.1"

julia> PyPlot.PyCall.python
"/anaconda/bin/python"

I already did an update by Pkg.update(), it seems that there are some packages in my julia keeping PyCall and PyPlot from updating. Maybe the new version is the root of the problem? I will try to update my packages and report again.

No it has nothing to do with PyPlot.jl and PyCall.jl. It’s the matplotlib version as I mentioned above.

So how would I swap my PyPlot backend within the Julia environment?

do ENV["MPLBACKEND"]="tkagg" (or whatever) before your first call on figure()

1 Like

I think I"m missing something:

julia> using PyPlot

julia> PyPlot.backend
"Qt5Agg"

julia> ENV["MPLBACKEND"]="tkagg"
"tkagg"

julia> PyPlot.backend
"Qt5Agg"

julia> ENV["MPLBACKEND"]="tkagg" 
"tkagg"

julia> PyPlot.backend
"Qt5Agg"

Try changing the environment variable before loading PyPlot.

Try changing the environment variable before loading PyPlot.

Yes, that is indeed the correct instruction. Sorry for not being precise enough. /Paul S

Got it. Works and the slowdown has gone away. How can I change the default backend so that I don’t have to use that command every time?

Put ENV["MPLBACKEND"]="tkagg" in your .juliarc.jl file and it will be loaded upon julia startup.

Put your backend preference in your matplotlibrc file (google for instructions on matplotlibrc)