Plots.jl with GR: exporting to PDF

Exporting to PDF by savefig() cuts off part of the (vertical) axis label in the resulting PDF file.

Is there a way to increase the size of the resulting bounding box or at least to manipulate the relative distance of the labels from the axes?

Tnx!!
MG


using Plots
using LaTeXStrings

gr(size=(400,400), legend= false)


x = 0:10
y = x.^2

plot(x,y)

xlabel!(L"x")
ylabel!(L"x^2")

savefig("mytestplot.pdf")

Seems like a bug with the margin computation and having LaTeX in the axis labels. If there is no issue already it’s probably worth opening one.

Normally you can play with the keyword left_margin, for example:

using Plots.Measures
plot(x, y, left_margin = 3mm)

but I’m afraid it won’t help you in this case as it controls the distance between axis label and axis (it would help if for example the problem was that the axis label overlaps with the tick labels).

Did not work (I had forgotten to include “using Plots.Measures”)…
I am temporarily solving this issue by

L"....   x^2"

(or replacing the dots with a random letter)

Turned out to be a bug in GR (or at least there is a related bug in GR):

https://github.com/jheinen/GR.jl/issues/92

Thank you!
I tried but searched for it in the wrong place (issues in “Plots.jl” and in “LaTeXStrings.jl”).

May I ask you how …you spotted Plots.Measures ? I have almost 20 years of experience with Matlab (and with reading documentation) but it seems it is immensely difficult for me to browse Julia docs and, in particular, Julia’s plotting docs.

I think there are two general issues: one (of which I’m guilty myself) is that Plots.jl contributors find many things very intuitive after a while and it’s difficult to tell what would be difficult/hard to find for a user; the other is that the community is much smaller than matlab’s, so googling is less helpful.

Other than browsing the docs, a very good tool is plotattr:

julia> plotattr()
Specify an attribute type to get a list of supported attributes. Options are Series, Subplot, Plot, Axis

julia> plotattr(:Subplot)
Defined Subplot attributes are:
annotations, aspect_ratio, background_color_inside, background_color_legend, background_color_subplot, bottom_margin, camera, clims, color_palette, colorbar, colorbar_title, fontfamily_subplot, foreground_color_legend, foreground_color_subplot, foreground_color_title, framestyle, left_margin, legend, legendfontcolor, legendfontfamily, legendfonthalign, legendfontrotation, legendfontsize, legendfontvalign, legendtitle, margin, projection, right_margin, subplot_index, title, title_location, titlefontcolor, titlefontfamily, titlefonthalign, titlefontrotation, titlefontsize, titlefontvalign, top_margin

julia> plotattr("margin")
margin {Measure (multiply by `mm`, `px`, etc)}

Base for individual margins... not directly used.  Specifies the extra padding around subplots.
Subplot attribute,  default: 1.0mm

Though it doesn’t specify that you need using Measures or using Plots.Measures to have access to mm or cm.

If you don’t find what you’re looking for in the docs, you can ask in the gitter channel (or on slack) and you’ll probably receive an answer reasonably quickly. If you find that something relevant is missing from the docs, a PR to improve documentation is always very welcome (Plots.jl has an insane amount of features and even for its developers is hard to know all of them).