# Plot limit at next tick label

**URL:** https://discourse.julialang.org/t/plot-limit-at-next-tick-label/27704
**Category:** General Usage
**Tags:** plotting, visualization
**Created:** [August 19, 2019, 7:43am UTC](https://discourse.julialang.org/t/plot-limit-at-next-tick-label/27704 "2019-08-19T07:43:24Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![aahaselgrove](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aahaselgrove/32/9839_2.png) [@aahaselgrove](https://discourse.julialang.org/u/aahaselgrove)
#### Post date: [August 19, 2019, 7:43am UTC](https://discourse.julialang.org/t/plot-limit-at-next-tick-label/27704/1 "2019-08-19T07:43:24Z")

</div>

I would like my plot axes to end at a tick label. How best may this be accomplished?

Nice-looking plot:

```julia
using Plots
using Random
Random.seed!(0)
time = 0:20
spend = 0.8 * rand(21)
bar(time, spend,
    title="Spend over time",
    xlabel="Year",
    ylabel="Spend",
    yformatter=y->"\$$y")

```

![Figure_1](https://global.discourse-cdn.com/julialang/original/3X/5/6/5614c7e5187b558a9a59dc82138b4cb4c32db7f4.png)

Less-nice-looking plot:

```julia
using Random
using Plots
pyplot()

Random.seed!(4)
time = 0:20
spend = 0.8 * rand(21)
bar(time, spend,
    title="Spend over time",
    xlabel="Year",
    ylabel="Spend",
    yformatter=y->"\$$y")

```

---

<div class="post-metadata">

### Author: ![aahaselgrove](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aahaselgrove/32/9839_2.png) [@aahaselgrove](https://discourse.julialang.org/u/aahaselgrove)
#### Post date: [August 19, 2019, 7:45am UTC](https://discourse.julialang.org/t/plot-limit-at-next-tick-label/27704/2 "2019-08-19T07:45:21Z")

</div>

Plot 2  
 ![Figure_1](https://global.discourse-cdn.com/julialang/original/3X/7/9/7930499bbeac1c11c8145b96fcc84ed5f096f8e4.png)

---

<div class="post-metadata">

### Author: ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)
#### Post date: [August 21, 2019, 1:13am UTC](https://discourse.julialang.org/t/plot-limit-at-next-tick-label/27704/3 "2019-08-21T01:13:46Z")

</div>

Welcome to the community! Please take a look at [this post](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757), which has some suggestions about how to make it easier for folks to help you when you ask questions on discourse. In particular you can quote entire blocks of code. It looks like you figured out how to do it for a single line with backticks, but you can use three of them to do a block:

````julia
```
function foo(x)
    return x + 42
end
```

````

Or you can just highlight it and click the button that looks like this: `</>`.

As you your actual question, i don’t think there’s a way to do this automatically, but you can set the ticks and limits manually. I think it’s something like `yaxis = ("Spend", 0:0.2:0.8, (0, 0.8))` (or separately, `ylabel= "Spend", yticks=0:0.2:0.8, ylims=(0, 0.8))`.

---

<div class="post-metadata">

### Author: ![aahaselgrove](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aahaselgrove/32/9839_2.png) [@aahaselgrove](https://discourse.julialang.org/u/aahaselgrove)
#### Post date: [August 21, 2019, 2:34am UTC](https://discourse.julialang.org/t/plot-limit-at-next-tick-label/27704/4 "2019-08-21T02:34:56Z")

</div>

Thanks for that - somehow I missed that the right panel was a preview. (Now that I’m typing this, I see that the ‘welcome to JuliaLang’ message obscures the right panel and doesn’t fade on its own, so I guess that’s how I missed it.) I’ve updated the code block formatting.

I understand that the plot limits may be set manually, but I was looking for an automated way to do this, if one existed. Alternatively, if there was any way to leverage functionality from something like optimal\_ticks\_and\_labels in Plots.jl, this would also be a great solution.

---

<div class="post-metadata">

### Author: ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)
#### Post date: [August 21, 2019, 10:19am UTC](https://discourse.julialang.org/t/plot-limit-at-next-tick-label/27704/5 "2019-08-21T10:19:52Z")

</div>

> [@aahaselgrove](#):
>
> Alternatively, if there was any way to leverage functionality from something like optimal\_ticks\_and\_labels

There is a way to get the properties of a plot after it’s created (I don’t remember off the top of my head what it is), and you could maybe use that to figure out whether the limits are appropriate. I haven’t spent much time with the internals of the pipeline, but I don’t think it’s possible to do this automatically.

That said, I think having more uniform ticks that end at the limits would be an improvement that might be worth opening an issue or PR for.
