# Slow REPL after PyPlot

**URL:** <https://discourse.julialang.org/t/slow-repl-after-pyplot/7862>\
**Category:** Performance\
**Tags:** plotting, pyplot\
**Created:** [December 19, 2017, 10:06pm UTC](https://discourse.julialang.org/t/slow-repl-after-pyplot/7862 "2017-12-19T22:06:02Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![gideonsimpson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gideonsimpson/32/1928_2.png) [@gideonsimpson](https://discourse.julialang.org/u/gideonsimpson)\
**Post date:** [December 19, 2017, 10:06pm UTC](https://discourse.julialang.org/t/slow-repl-after-pyplot/7862/1 "2017-12-19T22:06:02Z")

</div>

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:

```julia
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`

---

<div class="post-metadata">

**Author:** ![Non-Contradiction](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-contradiction/32/2208_2.png) [@Non-Contradiction](https://discourse.julialang.org/u/Non-Contradiction)\
**Post date:** [December 19, 2017, 11:42pm UTC](https://discourse.julialang.org/t/slow-repl-after-pyplot/7862/2 "2017-12-19T23:42:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gideonsimpson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gideonsimpson/32/1928_2.png) [@gideonsimpson](https://discourse.julialang.org/u/gideonsimpson)\
**Post date:** [December 20, 2017, 12:10am UTC](https://discourse.julialang.org/t/slow-repl-after-pyplot/7862/3 "2017-12-20T00:10:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [December 20, 2017, 3:46am UTC](https://discourse.julialang.org/t/slow-repl-after-pyplot/7862/4 "2017-12-20T03:46:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pwstokes225](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pwstokes225/32/17868_2.png) [@pwstokes225](https://discourse.julialang.org/u/pwstokes225)\
**Post date:** [December 20, 2017, 5:23am UTC](https://discourse.julialang.org/t/slow-repl-after-pyplot/7862/5 "2017-12-20T05:23:59Z")

</div>

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:

```julia
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:

```julia
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

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

```

in which case I have

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

```

---

<div class="post-metadata">

**Author:** ![Yifan\_Liu](https://avatars.discourse-cdn.com/v4/letter/y/4da419/32.png) [@Yifan\_Liu](https://discourse.julialang.org/u/Yifan_Liu)\
**Post date:** [December 20, 2017, 5:40am UTC](https://discourse.julialang.org/t/slow-repl-after-pyplot/7862/6 "2017-12-20T05:40:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [December 20, 2017, 7:51am UTC](https://discourse.julialang.org/t/slow-repl-after-pyplot/7862/7 "2017-12-20T07:51:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [December 20, 2017, 1:41pm UTC](https://discourse.julialang.org/t/slow-repl-after-pyplot/7862/8 "2017-12-20T13:41:14Z")

</div>

> [@Paul\_Soderlind](#):
>
> I also noticed this on matplotlib 2.1.1 (not earlier), when I use “qt5agg.” Switching to “tkagg” solved this problem.

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?

---

<div class="post-metadata">

**Author:** ![gideonsimpson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gideonsimpson/32/1928_2.png) [@gideonsimpson](https://discourse.julialang.org/u/gideonsimpson)\
**Post date:** [December 20, 2017, 3:55pm UTC](https://discourse.julialang.org/t/slow-repl-after-pyplot/7862/9 "2017-12-20T15:55:23Z")

</div>

```julia
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"

```

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [December 20, 2017, 3:56pm UTC](https://discourse.julialang.org/t/slow-repl-after-pyplot/7862/10 "2017-12-20T15:56:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Non-Contradiction](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-contradiction/32/2208_2.png) [@Non-Contradiction](https://discourse.julialang.org/u/Non-Contradiction)\
**Post date:** [December 20, 2017, 4:23pm UTC](https://discourse.julialang.org/t/slow-repl-after-pyplot/7862/11 "2017-12-20T16:23:39Z")

</div>

Still, I don’t have this issue with

```julia
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.

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [December 20, 2017, 4:33pm UTC](https://discourse.julialang.org/t/slow-repl-after-pyplot/7862/12 "2017-12-20T16:33:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gideonsimpson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gideonsimpson/32/1928_2.png) [@gideonsimpson](https://discourse.julialang.org/u/gideonsimpson)\
**Post date:** [December 20, 2017, 6:07pm UTC](https://discourse.julialang.org/t/slow-repl-after-pyplot/7862/13 "2017-12-20T18:07:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [December 20, 2017, 6:17pm UTC](https://discourse.julialang.org/t/slow-repl-after-pyplot/7862/14 "2017-12-20T18:17:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gideonsimpson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gideonsimpson/32/1928_2.png) [@gideonsimpson](https://discourse.julialang.org/u/gideonsimpson)\
**Post date:** [December 20, 2017, 6:47pm UTC](https://discourse.julialang.org/t/slow-repl-after-pyplot/7862/15 "2017-12-20T18:47:48Z")

</div>

I think I"m missing something:

```julia
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"

```

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [December 20, 2017, 6:57pm UTC](https://discourse.julialang.org/t/slow-repl-after-pyplot/7862/16 "2017-12-20T18:57:55Z")

</div>

Try changing the environment variable _before_ loading PyPlot.

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [December 20, 2017, 7:45pm UTC](https://discourse.julialang.org/t/slow-repl-after-pyplot/7862/17 "2017-12-20T19:45:30Z")

</div>

> Try changing the environment variable before loading PyPlot.

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

---

<div class="post-metadata">

**Author:** ![gideonsimpson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gideonsimpson/32/1928_2.png) [@gideonsimpson](https://discourse.julialang.org/u/gideonsimpson)\
**Post date:** [December 21, 2017, 2:41am UTC](https://discourse.julialang.org/t/slow-repl-after-pyplot/7862/18 "2017-12-21T02:41:00Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [December 21, 2017, 7:16am UTC](https://discourse.julialang.org/t/slow-repl-after-pyplot/7862/19 "2017-12-21T07:16:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [December 21, 2017, 1:04pm UTC](https://discourse.julialang.org/t/slow-repl-after-pyplot/7862/20 "2017-12-21T13:04:22Z")

</div>

> [@gideonsimpson](#):
>
> 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 your backend preference in your matplotlibrc file (google for instructions on matplotlibrc)

[Next page](https://discourse.julialang.org/t/slow-repl-after-pyplot/7862.md?page=2)
