# Something makes y-axis range too wide

**URL:** <https://discourse.julialang.org/t/something-makes-y-axis-range-too-wide/41092>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [June 9, 2020, 8:26pm UTC](https://discourse.julialang.org/t/something-makes-y-axis-range-too-wide/41092 "2020-06-09T20:26:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [June 9, 2020, 8:26pm UTC](https://discourse.julialang.org/t/something-makes-y-axis-range-too-wide/41092/1 "2020-06-09T20:26:36Z")

</div>

Something is odd.`clearance max` (`0.9`) and `clearance min` (`0.522`) are supposed to be constant throughout my simulation, so they should be straight lines, which they are. The strange thing is when plotting them, the y axis are much larger than they need to be.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/c/cc24ceef073688502fe422970266ab6675f28c12.png)

I am using Julia 1.4.2 and `Plots.jl` and all my other graphs look normal. Is it possible to have non-recorded (invisible) values of `clearance max` and `clearance min` that confuse Julia (now I sound like a conspiracy theorist)? This occurs even if I restart Julia and it is the first plot I make.

I can’t provide a MWE but I suspect the problem may lie with this nested part of my differential equation. Even though it is designed to prevent the clearance rate from going over `clearance max`, it still does.

```julia
        if clearance_V_type == 4
            if (revenue - cost_F) > 0.0
                limit = clearance_max
                effect = abs(max(0.0, (limit - clearance_V)))
            else
                limit = clearance_min
                effect = abs(min(0.0, (limit - clearance_V)))
            end
            dB[num_nutrient+num_plant+num_animal+num_vessel_types+1] = 365.25*µ*(revenue - cost_F)*effect
            clearance_V = bioS[num_nutrient+num_plant+num_animal+num_vessel_types+1]
            global db_clearance = dB[num_nutrient+num_plant+num_animal+num_vessel_types+1] # this is global because unfortunately I need it in the global scope so I can save the value
        end

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [June 10, 2020, 5:48am UTC](https://discourse.julialang.org/t/something-makes-y-axis-range-too-wide/41092/2 "2020-06-10T05:48:40Z")

</div>

> [@HelgavonLichtenstein](#):
>
> I can’t provide a MWE but I suspect the problem may lie with this nested part of my differential equation.

Try to save the actual `(x, y)` data you are plotting and inspect it, eg `extrema(y)`.

---

<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:** [June 10, 2020, 9:52am UTC](https://discourse.julialang.org/t/something-makes-y-axis-range-too-wide/41092/3 "2020-06-10T09:52:29Z")

</div>

If Plots can’t figure out the y axis limits from the data given (which is the case when your curve is constant) it just adds 1.  
The solution is to explicitly set the `ylims` you want to have.

---

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [June 10, 2020, 9:56am UTC](https://discourse.julialang.org/t/something-makes-y-axis-range-too-wide/41092/4 "2020-06-10T09:56:04Z")

</div>

Neat! I didn’t know that.
