# 'using Plots' takes 20 seconds or more

**URL:** <https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061>\
**Category:** Performance\
**Tags:** plotting\
**Created:** [November 14, 2017, 8:12am UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061 "2017-11-14T08:12:33Z")\
**Posts on this page:** 11\
**Page:** 2

<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:** [November 17, 2020, 12:34am UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/21 "2020-11-17T00:34:46Z")

</div>

In that case, you will see a very major improvement once 1.6 is released. A ton of work has gone into this in the past half year or so, an it remains one of the main developer priorities.

---

<div class="post-metadata">

**Author:** ![Volker\_Weissmann](https://avatars.discourse-cdn.com/v4/letter/v/c2a13f/32.png) [@Volker\_Weissmann](https://discourse.julialang.org/u/Volker_Weissmann)\
**Post date:** [November 17, 2020, 12:35am UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/22 "2020-11-17T00:35:32Z")

</div>

Ok, thank you.

---

<div class="post-metadata">

**Author:** ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Post date:** [November 17, 2020, 2:20am UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/23 "2020-11-17T02:20:29Z")

</div>

This is a serious tip. Installed in \<\<1min, precompiled in \<6s, plotted in \<4s.

I do love what Plots.jl offers, but - for more routine poking around this may be my go to.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [November 25, 2020, 7:57pm UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/24 "2020-11-25T19:57:57Z")

</div>

> [@Volker\_Weissmann](#):
>
> > $ time julia -e “using Plots”
> 
> > $ time python -c “import matplotlib”

I want to point out, these aren’t strictly comparable. In julia, the latter is same as `using PyPlot`. It gives you MATLAB-compatible plotting, in fact, the exact same as matplotlib (as you use that through Python).

Yes, it’s still a bit slower to start up, while GR.jl’s is comparable to matplotlib:

```julia
$ time julia -O0 -e "using GR"

real	0m0,310s

```

It’s the default backend for Plots.jl, and you can use it alone, without the abstraction of Plots. It’s fast since it’s already compiled code (i.e. non-Julia code, yes, plus some minimal Julia wrapper code), in that sense comparable, and faster, than the Python situation:

I’m not sure what’s the go-to Python plotting abstraction library, or if there is one, and most people use that one option.

In theory the wrapper, Plots.jl, and all Julia-only code, could be fully compiled. Currently it’s (partially) precompiled.

---

<div class="post-metadata">

**Author:** ![Volker\_Weissmann](https://avatars.discourse-cdn.com/v4/letter/v/c2a13f/32.png) [@Volker\_Weissmann](https://discourse.julialang.org/u/Volker_Weissmann)\
**Post date:** [November 25, 2020, 9:51pm UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/25 "2020-11-25T21:51:11Z")

</div>

I know that the three examples are not exactly the same. I should have wrote: “using Plots” takes long compared to the startup times of common C or python libraries.

> [@Palli](#):
>
> It gives you MATLAB-compatible plotting

Do you mean matplotlib compatible?

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [November 25, 2020, 10:45pm UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/26 "2020-11-25T22:45:24Z")

</div>

> Do you mean matplotlib compatible?

Yes, which is compatible with MATLAB.\* See: [GitHub - JuliaPy/PyPlot.jl: Plotting for Julia based on matplotlib.pyplot](https://github.com/JuliaPy/PyPlot.jl) (and matplotlib’s docs):

> In general, all of the arguments, including keyword arguments, are exactly the same as in Python. (With minor translations, of course, e.g. Julia uses `true` and `nothing` instead of Python’s `True` and `None` .)
> 
> The full `matplotlib.pyplot` API is far too extensive to describe here; see the [matplotlib.pyplot documentation for more information](http://matplotlib.org/api/pyplot_api.html).

To clarify, Python’s matplotlib is a moving target. I just know what the documentation says. It seems to be a full wrapper, but let’s say something gets added to the Python side, then I’m not sure how PyPlot keep up (for new interfaces that is, bugfixes that do not change the interface likely just get upgraded).

`*` I did write MATLAB-compatible on purpose, meaning matplotlib (and thus PyPlot indirectly) a (supposed) clone, i.e. both compatible with MATLAB’s plotting.

I wouldn’t use the word “compatible” for PyCall in relation to matplotlib, implying trying to be, when it should be identical, using the same code.

I guess MATLAB’s plotting is also a moving target, and while PyPlot.jl is hopefully compatible with it, it’s to the same degree as Python’s matplotlib, no more. I.e. it’s supposedly compatible, or do I just assume?

I did try to look up matplotlib’s docs and I can’t find MATLAB mentioned, maybe for trademark reasons.

I’ve ported code from MATLAB to Julia, including plotting code, and the interface seemed similar, I had to skip some, e.g. “hold on” that I didn’t immediately see how to do (it’s neither legal syntax in Julia nor Python, maybe I just overlooked how to do this).

You can even use the MATLAB engine, call using MATLAB.jl, to call code for computation (I didn’t try to get it to plot, I do not think appropriate for that, I might be wrong, unlike you can do by calling Python).

Let’s say PyPlots’s wrapper gets outdated, you could use matplotlib directly through PyCall.jl. PyPlot uses it, just to make the interface like native Julia, but it’s not at all hard to use any Python code directly.

---

<div class="post-metadata">

**Author:** ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Post date:** [November 25, 2020, 11:10pm UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/27 "2020-11-25T23:10:08Z")

</div>

Upgrading to Julia 1.5.3 :

```julia
julia> @time using Plots
@time plot(rand 8.158916 seconds (10.53 M allocations: 651.018 MiB, 2.86% gc time)

julia> @time plot(randn(20))
  2.671723 seconds (4.52 M allocations: 235.500 MiB, 2.44% gc time)

```

This is a huge improvement to what I was getting before and is tolerable. Excited to see 1.6!

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [November 25, 2020, 11:19pm UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/28 "2020-11-25T23:19:06Z")

</div>

> [@Palli](#):
>
> I’m not sure what’s the go-to Python plotting abstraction library, or if there is one, and most people use that one option.

To answer my own question here, it seems like matplotlib is it!

PyPlot has GR.jl as default backend, and matplotlib optional, but matplotlib also has backends, and gr is one of it. And [mplcairo](https://github.com/anntzer/mplcairo) is another. I didn’t look into what’s their default, maybe it’s gr, so it’s just about the API.

[Note, there seems also to be a GUI backend to it, I found code to query and change it.]

[https://matplotlib.org/thirdpartypackages/index.html#rendering-backends](https://matplotlib.org/thirdpartypackages/index.html#rendering-backends)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 27, 2020, 7:58am UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/29 "2020-11-27T07:58:28Z")

</div>

> [@anon92994695](#):
>
> Excited to see 1.6!

```julia
julia> @time using Plots
  4.004548 seconds (6.43 M allocations: 468.557 MiB, 5.07% gc time, 21.25% compilation time)

julia> @time plot(randn(20))
  3.104825 seconds (3.29 M allocations: 201.521 MiB, 7.70% gc time, 99.69% compilation time)

julia> VERSION
v"1.6.0-DEV.1581"

```

Note that this is a not-so-powerful laptop.

---

<div class="post-metadata">

**Author:** ![pablosanjose](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablosanjose/32/7006_2.png) [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Post date:** [November 27, 2020, 8:40am UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/30 "2020-11-27T08:40:37Z")

</div>

I see this on my Macbook Pro

```julia
julia> @time using Plots
  2.814411 seconds (5.89 M allocations: 422.216 MiB, 5.13% gc time, 19.86% compilation time)

julia> @time plot(randn(20))
  2.296894 seconds (3.50 M allocations: 208.185 MiB, 11.26% gc time, 99.48% compilation time)

julia> VERSION
v"1.6.0-DEV.1532"

```

This plus Revise essentially solves the plotting problem for me. v1.6 is simply amazing.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [November 27, 2020, 12:17pm UTC](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061/31 "2020-11-27T12:17:39Z")

</div>

Unfortunately that is not always true. With GMT I see a regression.

```julia
julia> @time using GMT
  0.998829 seconds (1.10 M allocations: 65.532 MiB, 1.60% gc time)

julia> @time plot([0.0 0; 1.1 1])
  3.602529 seconds (1.02 M allocations: 53.377 MiB, 0.45% gc time)

julia> VERSION
v"1.5.3"

```

and

```julia
julia> @time using GMT
  1.111520 seconds (1.43 M allocations: 89.916 MiB, 2.97% gc time, 54.24% compilation time)

julia> @time plot([0.0 0; 1.1 1])
  4.578288 seconds (3.74 M allocations: 174.832 MiB, 2.10% gc time, 99.43% compilation time)

julia> VERSION
v"1.6.0-DEV.1479"

```

[Previous page](https://discourse.julialang.org/t/using-plots-takes-20-seconds-or-more/7061.md?page=1)
