# Access y/xlim of a plot in Plots

**URL:** <https://discourse.julialang.org/t/access-y-xlim-of-a-plot-in-plots/11236>\
**Category:** Visualization\
**Tags:** question\
**Created:** [May 29, 2018, 2:46pm UTC](https://discourse.julialang.org/t/access-y-xlim-of-a-plot-in-plots/11236 "2018-05-29T14:46:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [May 29, 2018, 2:46pm UTC](https://discourse.julialang.org/t/access-y-xlim-of-a-plot-in-plots/11236/1 "2018-05-29T14:46:28Z")

</div>

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.

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

```

results in:

![b](https://global.discourse-cdn.com/julialang/original/3X/5/e/5e2b0166fa02d7d6610dca22e092ba113d6c1ab7.png)

and I want something similar to this:

![c](https://global.discourse-cdn.com/julialang/original/3X/7/1/713af047e993dbf7abee46fe3d5bb7286570db4f.png)

One idea is to control the `size` of the plot to fit the `x-` and `ylim`s.

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

```

which indeed results in this:

![b](https://global.discourse-cdn.com/julialang/original/3X/8/d/8d07ef486b75661200c65ae2d0e9e7cc9b44a5a1.png)

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 `ylim`s of the plot…

Any idea how I can do that?

---

<div class="post-metadata">

**Author:** ![cepheid](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cepheid/32/24934_2.png) [@cepheid](https://discourse.julialang.org/u/cepheid)\
**Post date:** [July 7, 2021, 8:45am UTC](https://discourse.julialang.org/t/access-y-xlim-of-a-plot-in-plots/11236/2 "2021-07-07T08:45:09Z")

</div>

This is also what I need. Any idea?

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [July 7, 2021, 9:47am UTC](https://discourse.julialang.org/t/access-y-xlim-of-a-plot-in-plots/11236/3 "2021-07-07T09:47:27Z")

</div>

After plotting do:

```julia
xlims()
ylims()

```
