Plots.jl is an interface for many different backends. But which backend to choose?
Each one supports different features, outputs slightly differently, and takes up different amounts of resources. Below, you will see three different plots generated for each of the different backends I tried to get working. I have historically used pyplot, gr, and plotlyjs, so those were already working for me. The pdfplots, unicodeplots, and inspectdr did not work out of the box. If you have timing information on these, feel free to contribute to this repsitory.
Julia optimizes and compiles a function the first time it runs, and the macro @time reflects that. Therefore, I run the function twice, and take the data reported on the second run.
Thanks to @jheinan for pointing out that I needed to use backend(show=true) to compute both the interface and the backend computation costs, and not just the interface costs.
I'll first run on a very simple function:
plot(x,y)
Remember that though @time returned a time and memory usage for pgfplots, unicodeplots, and inspectdr, none of these backends worked for me.
| Backend | Time | Mem |
|---|---|---|
| pyplot | .28 | 452 kB |
| gr | .01 | 166 kB |
| plotlyjs | .25 | 743 kB |
| unicodeplots | .18 | 2.7 Mb |
Next, I'll compare on something more intensize:
heatmap(z2d,
title="title",
xlabel="xlabel",
ylabel="ylabel",
seriescolor=:viridis
)
annotate!(50,50,"Hi! How long with this take?")
Neither pgfplots, unicodeplots, nor inspectdr support heatmap. While for the first test, the plots looked quite similiar, in this test, differences in how they place and render things start to show.
| Backend | Time | Mem |
|---|---|---|
| pyplot | .98 | 1.2 MiB |
| gr | .2 | 5.8 MiB |
| plotlyjs | .11 | 7.8 Mb |
My third function
plot(x,y1,linetype=:sticks)
plot!(x,y2,line=:dot)
plot!(x,y3,width=10,linealpha=.2)
scatter!(x,y4,marker=Shape(custom_marker))
also posed issues for pgfplots, unicodeplots, and inspectdr.
| Backend | Time | Mem |
|---|---|---|
| pyplot | 1.29 | 2 MiB |
| gr | .07 | 1.7 MiB |
| plotlyjs | .03 | 2.7 MB |
Plotlyjs would not support a custom marker.
In [1]:
using Plots
In [2]:
x=collect(0:.1:4π);
y=cos.(x);
In [3]:
pyplot(show=true)
@time plot(x,y)
@time plot(x,y)
Out[3]:
In [4]:
gr(show=true)
@time plot(x,y)
@time plot(x,y)
Out[4]:
In [5]:
plotlyjs(show=true)
@time plot(x,y)
@time plot(x,y)
Out[5]:
In [ ]:
pgfplots(show=true)
@time plot(x,y)
@time plot(x,y)
In [6]:
unicodeplots(show=true)
@time plot(x,y)
@time plot(x,y)
In [ ]:
inspectdr(show=true)
@time plot(x,y)
@time plot(x,y)
In [7]:
x2d=repmat(x,1,length(x))
y2d=repmat(transpose(x),length(x),1)
z2d=sin.(x2d).*sin.(y2d);
function plot2()
heatmap(z2d,
title="title",
xlabel="xlabel",
ylabel="ylabel",
seriescolor=:viridis
)
annotate!(50,50,"Hi! How long with this take?")
end
Out[7]:
In [8]:
pyplot(show=true)
@time plot2()
@time plot2()
Out[8]:
In [9]:
gr(show=true)
@time plot2()
@time plot2()
Out[9]:
In [11]:
plotlyjs(show=true)
@time plot2()
@time plot2()
Out[11]:
In [ ]:
pgfplots()
@time plot2()
@time plot2()
In [ ]:
unicodeplots()
@time plot2()
@time plot2()
In [ ]:
inspectdr()
@time plot2()
@time plot2()
In [12]:
x=collect(0:0.01:5)
y1=x;
y2=x.^2;
y3=10*sin.(x);
y4=randn(length(x));
custom_marker=[(-1,-1),
(-1,1),
(1,1),
(1,-1)];
function plot3()
plot(x,y1,linetype=:sticks)
plot!(x,y2,line=:dot)
plot!(x,y3,width=10,linealpha=.2)
scatter!(x,y4,marker=Shape(custom_marker))
end
Out[12]:
In [13]:
pyplot(show=true)
@time plot3()
@time plot3()
Out[13]:
In [14]:
gr(show=true)
@time plot3()
@time plot3()
Out[14]:
In [15]:
plotlyjs(show=true)
@time plot3()
@time plot3()
Out[15]:
In [ ]:
pgfplots()
@time plot3()
@time plot3()
In [ ]:
unicodeplots()
@time plot3()
@time plot3()
In [ ]:
inspectdr()
@time plot3()
@time plot3()
In [ ]: