Added an extrema(plt) which return the tuple (xmin, xmax), and changed abline! to use extrema.

This commit is contained in:
Patrick Kofod Mogensen 2016-02-03 10:35:36 +01:00
parent 5c4526725b
commit 1963fe208e
2 changed files with 4 additions and 2 deletions

View File

@ -132,7 +132,7 @@ end
"Adds a+bx... straight line over the current plot"
function abline!(plt::Plot, a, b; kw...)
plot!(plt, [xmin(plt), xmax(plt)], x -> b + a*x; kw...)
plot!(plt, [extrema(plt)...], x -> b + a*x; kw...)
end
abline!(args...; kw...) = abline!(current(), args...; kw...)
abline!(args...; kw...) = abline!(current(), args...; kw...)

View File

@ -471,3 +471,5 @@ xmin(plt::Plot) = minimum([minimum(d[:x]) for d in plt.seriesargs])
"Largest x in plot"
xmax(plt::Plot) = maximum([maximum(d[:x]) for d in plt.seriesargs])
"Extrema of x-values in plot"
Base.extrema(plt::Plot) = (xmin(plt), xmax(plt))