# How to get current x and y limits of a plot? (Plots.jl)

**URL:** <https://discourse.julialang.org/t/how-to-get-current-x-and-y-limits-of-a-plot-plots-jl/101029>\
**Category:** General Usage\
**Tags:** plots\
**Created:** [June 30, 2023, 6:09pm UTC](https://discourse.julialang.org/t/how-to-get-current-x-and-y-limits-of-a-plot-plots-jl/101029 "2023-06-30T18:09:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leespen1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leespen1/32/221928_2.png) [@leespen1](https://discourse.julialang.org/u/leespen1)\
**Post date:** [June 30, 2023, 6:09pm UTC](https://discourse.julialang.org/t/how-to-get-current-x-and-y-limits-of-a-plot-plots-jl/101029/1 "2023-06-30T18:09:53Z")

</div>

Given that I have already made a plot using, say `pl = plot([1,2,3])`, is there a way to query what the current x and y limits of the plot are?

E.g. something like `pl.xlims` which would return `(1.0,3.0)`.

I often find myself wanting to plot something abstract along with actual data, and this would be helpful for doing that while keeping the graph nice-looking. For example, I may be performing a numerical experiment and I want to plot step size vs error. To check the order convergence, I also want to plot lines of slopes 1, 2, 3, … (in log10 scale). But if I just do something like `plot!(step_sizes, step_sizes .^ 4)`, the line extends way past my data, making the window zoom out a lot more. If I knew the xlims and ylims when plotting, I could prevent this.

Alternatively, if there is some sort of option to plot new data _without adjusting the plot limits_, e.g. `pl = plot([1,2,3]); plot!(pl, [1,2,3,4,5,6], adjust_lims=false)`, and the second half of the second series just wouldn’t be visible in the window, that would also solve my problem.

---

<div class="post-metadata">

**Author:** ![leespen1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leespen1/32/221928_2.png) [@leespen1](https://discourse.julialang.org/u/leespen1)\
**Post date:** [June 30, 2023, 6:20pm UTC](https://discourse.julialang.org/t/how-to-get-current-x-and-y-limits-of-a-plot-plots-jl/101029/2 "2023-06-30T18:20:42Z")

</div>

It turns out you can do it using `xlims(pl)`.

On a related note, how am I supposed to discover functionality in Plots.jl? For example, I don’t know where to find a list of all the keywords I can supply to the `plot` function.

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [July 1, 2023, 5:22pm UTC](https://discourse.julialang.org/t/how-to-get-current-x-and-y-limits-of-a-plot-plots-jl/101029/3 "2023-07-01T17:22:05Z")

</div>

> [@leespen1](#):
>
> On a related note, how am I supposed to discover functionality in Plots.jl?

Either check the [attributes section](https://docs.juliaplots.org/stable/attributes/) and following of the documentation or call `plotattr()` in the REPL and explore via fuzzy finding.

---

<div class="post-metadata">

**Author:** ![leespen1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leespen1/32/221928_2.png) [@leespen1](https://discourse.julialang.org/u/leespen1)\
**Post date:** [July 5, 2023, 6:41pm UTC](https://discourse.julialang.org/t/how-to-get-current-x-and-y-limits-of-a-plot-plots-jl/101029/4 "2023-07-05T18:41:52Z")

</div>

Thanks!
