From 1963fe208e1aa1cba6ddb961cf1dc86e6103c43f Mon Sep 17 00:00:00 2001 From: Patrick Kofod Mogensen Date: Wed, 3 Feb 2016 10:35:36 +0100 Subject: [PATCH] Added an extrema(plt) which return the tuple (xmin, xmax), and changed abline! to use extrema. --- src/recipes.jl | 4 ++-- src/utils.jl | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/recipes.jl b/src/recipes.jl index 45309c12..adf59872 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -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...) \ No newline at end of file diff --git a/src/utils.jl b/src/utils.jl index 576f4970..90431042 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -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)) \ No newline at end of file