# How to use the output of log\_fit in abline plotted in a loglog plot in Julia

**URL:** <https://discourse.julialang.org/t/how-to-use-the-output-of-log-fit-in-abline-plotted-in-a-loglog-plot-in-julia/32562>\
**Category:** General Usage\
**Tags:** question, plotting\
**Created:** [December 21, 2019, 8:49pm UTC](https://discourse.julialang.org/t/how-to-use-the-output-of-log-fit-in-abline-plotted-in-a-loglog-plot-in-julia/32562 "2019-12-21T20:49:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![1634](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1634/32/12119_2.png) [@1634](https://discourse.julialang.org/u/1634)\
**Post date:** [December 21, 2019, 8:49pm UTC](https://discourse.julialang.org/t/how-to-use-the-output-of-log-fit-in-abline-plotted-in-a-loglog-plot-in-julia/32562/1 "2019-12-21T20:49:20Z")

</div>

Dear community,  
For log\_fit, the equation is log y=a+b\*log x, whose output coefficients are ‘a’ and ‘b’. Slope ‘b’ is applied in view of **log x** , so how can I plot the non-linear regression in a loglog plot on scale of **x**?

Another way is to use **log x** as the scale, but all other attributes of loglog plot need to be mannually set in this case, i.e. vertically asymmetric error bar and axis notation. It seems to be harder for me and clumsy.

> using CurveFit  
> coef=log\_fit(x,y)  
> using Plots  
> scatter(x, y, yerror=se, scale=:log10)  
> Plots.abline!(coef[2],coef[1],line=:dash)  
> Plots.abline!(coef[2],coef[1],line=:dash,scale=:log10)#made no difference  
> Plots.abline!(coef[2],coef[1],line=:dash,xaxis=:log10)#made no difference

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 22, 2019, 7:31am UTC](https://discourse.julialang.org/t/how-to-use-the-output-of-log-fit-in-abline-plotted-in-a-loglog-plot-in-julia/32562/2 "2019-12-22T07:31:20Z")

</div>

You could just calculate that curve directly, with something like

```julia
xgrid = range(extrema(x)...; length = 100)
ygrid = exp.(coef[1] .+ coef[2] .* log.(xgrid)) # check the order, I did not test this

```

and then plot the `xgrid, ygrid` curve.

---

<div class="post-metadata">

**Author:** ![1634](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1634/32/12119_2.png) [@1634](https://discourse.julialang.org/u/1634)\
**Post date:** [December 22, 2019, 9:32pm UTC](https://discourse.julialang.org/t/how-to-use-the-output-of-log-fit-in-abline-plotted-in-a-loglog-plot-in-julia/32562/3 "2019-12-22T21:32:51Z")

</div>

Thank you, your method should work but the coefficients output from log\_fit are weird (making the ygrid infinite). To make it repeatable, I attached the data in codes.

> #population size  
> x=[10 100 1000 10000]  
> #mean time of an allele to extinction or fixation  
> y= [23.06 245.48 2437.8 31245.775510204083]  
> se=[2.068502366645087 26.886795788176432 264.41256106505153 2811.6173148600947] #of mean y  
> using CurveFit  
> coef=log\_fit(x,y)  
> using Plots  
> scatter(x, y, yerror=se, scale=:log10,legend=false)
> 
> xgrid=range(extrema(x)…;length=100)  
> ygrid = exp.(coef[1] .+ coef[2] .\* log.(xgrid))  
> print(ygrid) #inf  
> plot!(xgrid,ygrid)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 23, 2019, 9:15am UTC](https://discourse.julialang.org/t/how-to-use-the-output-of-log-fit-in-abline-plotted-in-a-loglog-plot-in-julia/32562/4 "2019-12-23T09:15:46Z")

</div>

Check the docs of `log_fit`, it is for y = a\_1 + a\_2 \log(x).

---

<div class="post-metadata">

**Author:** ![1634](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/1634/32/12119_2.png) [@1634](https://discourse.julialang.org/u/1634)\
**Post date:** [December 23, 2019, 12:58pm UTC](https://discourse.julialang.org/t/how-to-use-the-output-of-log-fit-in-abline-plotted-in-a-loglog-plot-in-julia/32562/5 "2019-12-23T12:58:27Z")

</div>

I get it. Thank you for your patience~
