Access y/xlim of a plot in Plots

I’m plotting something with aspect_ratio=1 (GR backend) and the resulting file (via savefig) has a lot of “air” surrounding the plot. I want to make it a bit more tight.

using Plots
plot(rand(10), aspect_ratio = 1)
savefig("a.png")

results in:

b

and I want something similar to this:

c

One idea is to control the size of the plot to fit the x- and ylims.

w = 100
plot(rand(10), aspect_ratio = 1, size = (10w,1w))

which indeed results in this:

b

But because the plots in question include many different sources of data it’s not very trivial to know what the ranges of the axes are. It would therefore be easier to access the x- and ylims of the plot…

Any idea how I can do that?

This is also what I need. Any idea?

After plotting do:

xlims()
ylims()