Merge pull request #1300 from mkborregaard/master

RFC: abline! does not change axis limits; fix: #1297
This commit is contained in:
Michael Krabbe Borregaard 2017-12-11 12:12:52 +01:00 committed by GitHub
commit 0ef13dcf7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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...)