Large size of plot files generated using Plots.jl with GR backend

The sizes of the plot files generated by GR are sometimes ridiculously large. Changing dpi does not help significantly. After some experimenting, it seems it is caused by LaTeX text. For example

gr()
xi = 0:0.1:10
plot(xi,sin.(xi), xlabel=L"\sin\cos x_y", ylabel=L"\frac{42}{42}“, label=L”\mathcal N")
savefig(“fig.pdf”)

generates plot which has 1.94 MB. I have checked this behaviour on 2 computers. It is also the same when not using LaTeXStrings, like

ylabel = “$\sin $”

Does anyone know how to fix this problem?

LaTeX text is internally created using dvipng - so, this is the normal behaviour, as all math text is displayed using images.

Does anyone know how to fix this problem?

not really, but pyplot() produces small files. Need to replace \mathcal, though.

This is a reasonable advice, unfortunately after upgrading to Julia 1.0 I cannot make pyplot() working. Frankly, I would rather switch my project to Python instead of wasting time making Python work in Julia.

Maybe a hybrid: write results to the file and plot them in Python.

Yes, I mean, who would even consider using a programming language in which one of the plotting packages causes saved png files to be large? :troll:

1 Like

If you really want graphics with LaTeX, then this is perhaps a nice idea:

https://kristofferc.github.io/PGFPlotsX.jl/latest/examples/gallery.html#manual_gallery-1

2 Likes

Thank you, I know it, but I haven’t checked it in detail, maybe I should. The devil is in the details, I often need to tweak plots a lot, so the control options are crucial. I have hoped that Plots.jl could be easy to use and strong enough, but I am becoming increasingly doubtful. I tried doing what I can in Plots.jl and the rest in PyPlot.jl, but some options from matplotlib did not work. Then it stopped working althogether. For matplotlib at least I know it is (mostly) working and you really can change a lot…

If you really need all the control options, just use PyPlot (without Plots). That should give essentially the same experience as you have with matplotlib in Python. Plots is not as customisable.

I have tried. Basic stuff did work, but using some more advanced options resulted in errors.

If you want to get help, your best route is probably creating an MWE and reporting said errors.