Plots: margins, positions of axes, etc., within the canvas (paper)

What is the general method to control the positions of the axes in a plot?

Below is my first small attempt to push the upper x axis downward, which fails:

julia> using Plots

julia> plot(sin; top_margin=10mm)
ERROR: UndefVarError: `mm` not defined
Stacktrace:
 [1] top-level scope
   @ REPL[2]:1

julia> plotattr("top_margin")
Specifies the extra padding on the top of the subplot (`:match` matches `:margin`).

Aliases: (:top_margins, :topmargin, :topmargins).

Type: Union{Real, Symbol, Tuple}.

`Subplot` attribute, defaults to `match`.

julia>

My ultimate goal is to precisely control the end points of the axes within the “canvas” or “paper”.

For example, suppose that your final plot is a PDF image within a bounding box of (x_left, y_bottom, x_right, y_top) = (0, 0, 100mm, 80mm), and suppose that you want to place the four axes at x = 10mm and x = 90mm and y = 15mm and y = 70mm. What julia code would you write?

If it’s impossible to specify physical positions, what about relative, normalized positions? For example, suppose that your canvas is [0,1] x [0,1] and you want your axes at x = 0.1 and x = 0.9 and y = 0.1 and y = 0.7.

If it’s impossible to specify precise positions at all, what about moving the axes from their default positions?

1 Like