# How to set axes ranges based on one series but not another in Plots Recipe?

**URL:** https://discourse.julialang.org/t/how-to-set-axes-ranges-based-on-one-series-but-not-another-in-plots-recipe/5253
**Category:** Visualization
**Tags:** question, plots, recipe
**Created:** [August 7, 2017, 7:43am UTC](https://discourse.julialang.org/t/how-to-set-axes-ranges-based-on-one-series-but-not-another-in-plots-recipe/5253 "2017-08-07T07:43:00Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ValdarT](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/valdart/32/24146_2.png) [@ValdarT](https://discourse.julialang.org/u/ValdarT)
#### Post date: [August 7, 2017, 7:43am UTC](https://discourse.julialang.org/t/how-to-set-axes-ranges-based-on-one-series-but-not-another-in-plots-recipe/5253/1 "2017-08-07T07:43:00Z")

</div>

With the following code, the y-axis is based on the distribution and adding the vertical line does not change that.

```julia
using Distributions, StatPlots
gr()

dist = Normal(1,1)
p = plot(dist, fill=(0,0.5))
plot!(p, [mean(dist)], linetype=:vline, label="")

```

I would like to achieve the same behavior within a Plots Recipe but if I add a vertical line as a new series then it changes the y-axis range.

```julia
struct SomeWrapper{T<:Distributions.Distribution}
    dist::T
end

using RecipesBase

@recipe function f(foo::SomeWrapper)
    @series begin
      fill --> (0, 0.5)
      foo.dist
    end
    @series begin
      linetype --> :vline
      label --> ""
      [mean(foo.dist)]
    end
end

plot(SomeWrapper(Normal(1,1)))

```

How can I fix that (i.e., force the ylims to be based only on the first series)?

---

<div class="post-metadata">

### Author: ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)
#### Post date: [August 7, 2017, 9:29am UTC](https://discourse.julialang.org/t/how-to-set-axes-ranges-based-on-one-series-but-not-another-in-plots-recipe/5253/2 "2017-08-07T09:29:43Z")

</div>

I don’t think you can do that in this case, the problem is that the Distribution is interpreted as a function and, so the max value is calculated later in this case. You may have to set ylim manually.

---

<div class="post-metadata">

### Author: ![ValdarT](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/valdart/32/24146_2.png) [@ValdarT](https://discourse.julialang.org/u/ValdarT)
#### Post date: [August 7, 2017, 12:32pm UTC](https://discourse.julialang.org/t/how-to-set-axes-ranges-based-on-one-series-but-not-another-in-plots-recipe/5253/3 "2017-08-07T12:32:58Z")

</div>

Thanks for the quick reply!  
I wonder if it would be worth it to add to recipes the ability to refer to plot attributes that will be calculated later on. The ability to access, for example, `ylims()` after the first series would easily solve this case as well as make it easy to position annotations etc.

By the way, do you consider this a bug? I would expect the vline to behave the same way when added with `plot!()` or inside a recipe…

---

<div class="post-metadata">

### Author: ![ValdarT](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/valdart/32/24146_2.png) [@ValdarT](https://discourse.julialang.org/u/ValdarT)
#### Post date: [August 12, 2017, 3:35pm UTC](https://discourse.julialang.org/t/how-to-set-axes-ranges-based-on-one-series-but-not-another-in-plots-recipe/5253/4 "2017-08-12T15:35:47Z")

</div>

What are your thoughts on this, @mkborregaard?

---

<div class="post-metadata">

### Author: ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)
#### Post date: [August 13, 2017, 1:51pm UTC](https://discourse.julialang.org/t/how-to-set-axes-ranges-based-on-one-series-but-not-another-in-plots-recipe/5253/5 "2017-08-13T13:51:57Z")

</div>

I consider it a bug, but a hard one to fix.
