Changing distance between axes and x/y guides?

How do I change the space between the frame/ticks/ticks numbers and the x/y axis guides? E.g. in this case:

plot(x -> x^2,xguide="X-axis",yguide="Y-axis")


(red markings are added to me to show what distance I want to change)

Especially when one does subplots, the distance can become quite significant:

plot(plot(x -> x^2,xguide="X-axis",yguide="Y-axis"),plot(x -> x^3,xguide="X-axis",yguide="Y-axis"),size=(700,350))

image

2 Likes

For the 2nd case, a workaround: using Measures and add plot keyword argument to second subplot: left_margin=10mm

So, using

plot(plot(x -> x^2,xguide="X-axis",yguide="Y-axis"),plot(x -> x^3,xguide="X-axis",yguide="Y-axis",left_margin=10mm),size=(700,350))

partially solves it, in that the text is no longer closer to the left plot (than the right plot, to which it belongs):
image

However, the result is that you just get more space inbetweem and the space between the text and frame (of the right plot) does not change. The result is that you just get a very sparse plot, mostly filled with empty space, and less with the actual information.

As you did not specify the backend, take inspectdr(), where you can adjust the plot layout interactively (below is default look without editing):

using Plots; inspectdr()
plot(plot(x -> x^2, xguide="X-axis", yguide="Y-axis"),
     plot(x -> x^3, xguide="X-axis", yguide="Y-axis", size=(700,350)))

Think I am currently on gr (that’s the default?).

That looks really cool! Unfortunately, haven’t gotten those adjustment options, I run your code and get something like this:
image

I have tried it both in Jupyter and VSCode.

Please send the inspectdr() plot to an external window to get interactivity and some layout control. In VS Code settings untick this box.

That worked, thanks.

Great question, I’m having issues with this exact distance. It would be great if this distance could be modified with an axis attribute! My x- and y-axis labels / guides are much too far from their ticklabels, see below, and I don’t know how to fix this. I can replace all the labels by annotations, but this seems a poor hack.

1 Like

This actually would be a great feature. Especially in plots with a lot of subplots the distance between guide and axis is too large.

The simplest thing I would try first is:

  1. to add a line break at the end of the xlabel strings and two line breaks at the beginning of the ylabel strings;
  2. increase the margins by a few millimeters using Measures.
  3. Adjusting plot size and dpi
MWE
using Measures, Plots; gr(dpi=1200)
p = [plot(rand(10), rand(10), xlabel="xlabel\n", ylabel="\n\nylabel") for _ in 1:12]
plot(p..., layout=(3, 4), size=(1600,1200), margins=2mm)