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).
This commit is contained in:
Patrick Kofod Mogensen 2016-02-02 22:02:31 +01:00
parent b1c9d0a0af
commit 3f42e9c5bd
3 changed files with 13 additions and 0 deletions

View File

@ -59,6 +59,7 @@ export
path3d!,
scatter3d,
scatter3d!,
abline!,
title!,
xlabel!,

View File

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

View File

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