Skip to content

Commit

Permalink
Merge pull request #126 from pkofod/dev
Browse files Browse the repository at this point in the history
Add abline! which creates a straight line according to the formula b+…
  • Loading branch information
tbreloff committed Feb 3, 2016
2 parents b1c9d0a + 1963fe2 commit bce865f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export
path3d!,
scatter3d,
scatter3d!,
abline!,

title!,
xlabel!,
Expand Down
6 changes: 6 additions & 0 deletions src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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, [extrema(plt)...], x -> b + a*x; kw...)
end

abline!(args...; kw...) = abline!(current(), args...; kw...)
14 changes: 11 additions & 3 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -465,3 +465,11 @@ 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])

"Extrema of x-values in plot"
Base.extrema(plt::Plot) = (xmin(plt), xmax(plt))

0 comments on commit bce865f

Please sign in to comment.