Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's Julia's Plots.jl's equivalent of R's `abline`?

Tags:

julia

plots.jl

R's abline draws a straight line parameterised by y = ax+b on the x-y 2D coordinate plan.

What's Julia's equivalent of that in Plots.jl?

like image 537
xiaodai Avatar asked Oct 19 '25 05:10

xiaodai


1 Answers

There is Plots.abline! which draws a straight line in the form of ax+b respecting axis limits of the plot. So it will not actually go to infinity but does not require you to know what the axis limits are beforehand.

plot(x->((x^2+3x+2)/(x-2)), 6, 30, xlim=(6,30), size=(300,300))
# draw oblique asymptote to the above function (y=x+5)
Plots.abline!(1, 5, line=:dash)

You can also plot a straight line using only two points that are on the line. This should also respect the axis limits.

plot!([x1, x2], [y1, y2], seriestype = :straightline, kwargs...)
like image 85
hckr Avatar answered Oct 21 '25 04:10

hckr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!