'using Plots' takes 20 seconds or more

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.

6 Likes

Ok, thank you.

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.

2 Likes

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:

$ 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.

1 Like

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.

Do you mean matplotlib compatible?

Do you mean matplotlib compatible?

Yes, which is compatible with MATLAB.* See: GitHub - JuliaPy/PyPlot.jl: Plotting for Julia based on matplotlib.pyplot (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.

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.

Upgrading to Julia 1.5.3 :

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!

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

1 Like
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.

5 Likes

I see this on my Macbook Pro

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.

6 Likes

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

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> @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"
1 Like