From 5e5f3c1e957b295525e67bea1a87891b57b4273d Mon Sep 17 00:00:00 2001 From: "Michael K. Borregaard" Date: Mon, 11 Dec 2017 10:26:19 +0100 Subject: [PATCH] abline! does not change axis limits --- src/recipes.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/recipes.jl b/src/recipes.jl index 74711add..5eab486f 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -985,9 +985,11 @@ end # ------------------------------------------------- -"Adds a+bx... straight line over the current plot" +"Adds a+bx... straight line over the current plot, without changing the axis limits" function abline!(plt::Plot, a, b; kw...) - plot!(plt, [ignorenan_extrema(plt)...], x -> b + a*x; kw...) + xl, yl = xlims(plt), ylims(plt) + x1, x2 = max(xl[1], (yl[1] - b)/a), min(xl[2], (yl[2] - b)/a) + plot!(plt, x -> b + a*x, x1, x2; kw...) end abline!(args...; kw...) = abline!(current(), args...; kw...)