# Very slow Plots performance and... no plot

**URL:** <https://discourse.julialang.org/t/very-slow-plots-performance-and-no-plot/49064>\
**Category:** Performance\
**Tags:** plotting\
**Created:** [October 26, 2020, 7:15pm UTC](https://discourse.julialang.org/t/very-slow-plots-performance-and-no-plot/49064 "2020-10-26T19:15:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rnturn](https://avatars.discourse-cdn.com/v4/letter/r/f05b48/32.png) [@rnturn](https://discourse.julialang.org/u/rnturn)\
**Post date:** [October 26, 2020, 7:15pm UTC](https://discourse.julialang.org/t/very-slow-plots-performance-and-no-plot/49064/1 "2020-10-26T19:15:32Z")

</div>

Environment: openSUSE 15.1, downloaded Julia 1.5.2 (tar.gz).

I’m finding that using Plots (pun sort of intended) is really slow and when I use plot() in a script I get no output:

```julia
#plottest
using Dates
t0 = now()
using Plots
t1 = now()
plot( [cumsum( rand( 50 ) .- 0.5 ), cumsum( rand( 50 ) .- 0.5 )] )
t2 = now()
println( "using Plots took: ", t1 - t0 )
println( "plot() took: ", t2 - t1 )
println( "Overall: ", t2 - t0 )

```

When running this as in a terminal, I get:

```julia
$ time julia ./plottest
using Plots took: 11862 milliseconds
plot() took: 3847 milliseconds
Overall: 15709 milliseconds

real	0m15.876s
user	0m15.495s
sys	0m0.392s
$

```

If I include a “shebang” (either “#!/usr/bin/julia” or “#!/usr/bin/env julia”) in the script and run it, I get the same results: slowness and no plot. I’m only able to produce a plot when running julia interactively. (Not how I anticipated running Julia code long term.)

Q1: Is it normal for “using Plots” to take 10+ seconds when a script runs? Even working interactively, “using Plots” takes ~10s to complete. Plus, 3.8 seconds to plot 2 50-point data sets seems excessive as well. (Maybe cumsum() is the problem in that case?)

Q2: Why is no plot ever produced when plot() is run from a script? I only get the output from plot() when working at the “julia\>” prompt.

TIA…

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [October 26, 2020, 7:19pm UTC](https://discourse.julialang.org/t/very-slow-plots-performance-and-no-plot/49064/2 "2020-10-26T19:19:54Z")

</div>

> [@rnturn](#):
>
> Q1: Is it normal for “using Plots” to take 10+ seconds when a script runs? Even working interactively, “using Plots” takes ~10s to complete. Plus, 3.8 seconds to plot 2 50-point data sets seems excessive as well. (Maybe cumsum() is the problem in that case?)

Yes, it is. A lot of Plots functions get compiled on the first call of the package, and that takes some seconds. If you need to plot interactively keep you Julia section open. The second time you plot something (your second call to plot(…)) will be fast. This is getting better at each release, but still is not ideal.

> [@rnturn](#):
>
> Q2: Why is no plot ever produced when plot() is run from a script? I only get the output from plot() when working at the “julia\>” prompt.

When running from a script the plot is not shown interactively, because the script ends. You might want to add

```julia
savefig("./plot.pdf")

```

to save plot generated before the end of the script.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [October 26, 2020, 7:21pm UTC](https://discourse.julialang.org/t/very-slow-plots-performance-and-no-plot/49064/3 "2020-10-26T19:21:24Z")

</div>

Note that 1.6 should be at least 2x faster for time to load plots (the exact difference will depend on hardware and OS)

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [October 26, 2020, 7:24pm UTC](https://discourse.julialang.org/t/very-slow-plots-performance-and-no-plot/49064/4 "2020-10-26T19:24:06Z")

</div>

You’d need to call `display` on the plot object in a script to display the plot and then you’d need something to stop the script from terminating, like a `readline` at the end of the script. Otherwise you will see the plot only for a few microseconds.

---

<div class="post-metadata">

**Author:** ![schaerfo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/schaerfo/32/19024_2.png) [@schaerfo](https://discourse.julialang.org/u/schaerfo)\
**Post date:** [October 26, 2020, 7:40pm UTC](https://discourse.julialang.org/t/very-slow-plots-performance-and-no-plot/49064/5 "2020-10-26T19:40:55Z")

</div>

You may also want to check out the [PackageCompiler](https://github.com/JuliaLang/PackageCompiler.jl) package, it allows you to create a so-called sysimage that greatly speeds up the package loading and compilation.

---

<div class="post-metadata">

**Author:** ![rnturn](https://avatars.discourse-cdn.com/v4/letter/r/f05b48/32.png) [@rnturn](https://discourse.julialang.org/u/rnturn)\
**Post date:** [October 26, 2020, 8:28pm UTC](https://discourse.julialang.org/t/very-slow-plots-performance-and-no-plot/49064/6 "2020-10-26T20:28:47Z")

</div>

I suspected that it would be something like that. I’ll give a try in a few minutes.

Thanks.

---

<div class="post-metadata">

**Author:** ![rnturn](https://avatars.discourse-cdn.com/v4/letter/r/f05b48/32.png) [@rnturn](https://discourse.julialang.org/u/rnturn)\
**Post date:** [October 26, 2020, 8:29pm UTC](https://discourse.julialang.org/t/very-slow-plots-performance-and-no-plot/49064/7 "2020-10-26T20:29:24Z")

</div>

Good to know that better things are coming. Thanks…

---

<div class="post-metadata">

**Author:** ![rnturn](https://avatars.discourse-cdn.com/v4/letter/r/f05b48/32.png) [@rnturn](https://discourse.julialang.org/u/rnturn)\
**Post date:** [October 26, 2020, 8:30pm UTC](https://discourse.julialang.org/t/very-slow-plots-performance-and-no-plot/49064/8 "2020-10-26T20:30:38Z")

</div>

I haven’t gotten far enough into Julia to think about compilation but it is something that attracted me to the language. I’ll give that a look. Thanks…

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [October 26, 2020, 9:44pm UTC](https://discourse.julialang.org/t/very-slow-plots-performance-and-no-plot/49064/9 "2020-10-26T21:44:53Z")

</div>

Julia is still best uses interactively but if you do want to use Julia for scripting I’d consider [DaemonMode.jl](https://github.com/dmolina/DaemonMode.jl).  
The second time you run the plot script should be fast, just like the second time you plot from the REPL.
