From 3f42e9c5bd845184734dae8418b544af7d5b7954 Mon Sep 17 00:00:00 2001 From: Patrick Kofod Mogensen Date: Tue, 2 Feb 2016 22:02:31 +0100 Subject: [PATCH 1/3] Add abline! which creates a straight line according to the formula b+a*x, and export abline! Also add utility functions xmin(plt::Plot) and xmax(plt::Plot). --- src/Plots.jl | 1 + src/recipes.jl | 6 ++++++ src/utils.jl | 6 ++++++ 3 files changed, 13 insertions(+) diff --git a/src/Plots.jl b/src/Plots.jl index feca5ce9b..5dcd596d7 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -59,6 +59,7 @@ export path3d!, scatter3d, scatter3d!, + abline!, title!, xlabel!, diff --git a/src/recipes.jl b/src/recipes.jl index 44ba5d856..45309c124 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -130,3 +130,9 @@ function spy{T<:Real}(y::AMat{T}; kw...) heatmap(J, I; leg=false, yflip=true, nbins=size(y), kw...) 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...) +end + +abline!(args...; kw...) = abline!(current(), args...; kw...) diff --git a/src/utils.jl b/src/utils.jl index 68f205837..bf97febd4 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -465,3 +465,9 @@ mm2inch(mm::Real) = float(mm / MM_PER_INCH) px2mm(px::Real) = float(px * MM_PER_PX) mm2px(mm::Real) = float(px / MM_PER_PX) + +"Smallest x in plot" +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]) + From 5c4526725b6a2037abe54ddfc32a216a4d49d777 Mon Sep 17 00:00:00 2001 From: Patrick Kofod Mogensen Date: Wed, 3 Feb 2016 10:32:58 +0100 Subject: [PATCH 2/3] Remove trailing spaces. --- src/utils.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils.jl b/src/utils.jl index bf97febd4..576f49700 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -246,7 +246,7 @@ function with(f::Function, args...; kw...) oldbackend = CURRENT_BACKEND.sym for arg in args - + # change backend? if arg in backends() backend(arg) @@ -421,10 +421,10 @@ function supportGraph(allvals, func) push!(x, string(b)) push!(y, string(val)) end - end + end end n = length(vals) - + scatter(x,y, m=:rect, ms=10, From 1963fe208e1aa1cba6ddb961cf1dc86e6103c43f Mon Sep 17 00:00:00 2001 From: Patrick Kofod Mogensen Date: Wed, 3 Feb 2016 10:35:36 +0100 Subject: [PATCH 3/3] 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 45309c124..adf598729 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 576f49700..904310429 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