# Plot exponential fit

**URL:** <https://discourse.julialang.org/t/plot-exponential-fit/86455>\
**Category:** New to Julia\
**Tags:** plotting\
**Created:** [August 28, 2022, 11:04am UTC](https://discourse.julialang.org/t/plot-exponential-fit/86455 "2022-08-28T11:04:04Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mahmoud](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Mahmoud](https://discourse.julialang.org/u/Mahmoud)\
**Post date:** [August 28, 2022, 11:04am UTC](https://discourse.julialang.org/t/plot-exponential-fit/86455/1 "2022-08-28T11:04:04Z")

</div>

![276951087_1170690647003904_7499658712435214814_n](https://global.discourse-cdn.com/julialang/original/3X/2/a/2a53f54ed68721eb7e55ce8a380cc3739840c382.jpeg)  
 ![paper2](https://global.discourse-cdn.com/julialang/original/3X/6/8/685c9b1d5e886f0febd720575f1b7198c4a0702b.png)  
The first image is generated using julia  
the second one is generated using python  
How to make the first one like the second one ? how to include the exponential fit line and start the axis from 1 ??

---

<div class="post-metadata">

**Author:** ![ptoche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ptoche/32/23554_2.png) [@ptoche](https://discourse.julialang.org/u/ptoche)\
**Post date:** [August 28, 2022, 11:32am UTC](https://discourse.julialang.org/t/plot-exponential-fit/86455/2 "2022-08-28T11:32:43Z")

</div>

what’s your code?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [August 28, 2022, 11:48am UTC](https://discourse.julialang.org/t/plot-exponential-fit/86455/3 "2022-08-28T11:48:57Z")

</div>

Given that your plots looks like it’s been generated using the `Plots` package (there are many plotting packages in Julia, so it’s important to specify which one you are using when asking for help):

The y-axis limits are set using the `ylims` keyword, so `plot(days, infected, ylims = (1, 100))` will set y-axis limit to go from 1 to 100.

---

<div class="post-metadata">

**Author:** ![zdenek\_hurak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zdenek_hurak/32/53118_2.png) [@zdenek\_hurak](https://discourse.julialang.org/u/zdenek_hurak)\
**Post date:** [August 28, 2022, 12:45pm UTC](https://discourse.julialang.org/t/plot-exponential-fit/86455/4 "2022-08-28T12:45:23Z")

</div>

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [August 28, 2022, 1:32pm UTC](https://discourse.julialang.org/t/plot-exponential-fit/86455/5 "2022-08-28T13:32:55Z")

</div>

This post was temporarily hidden by the community for possibly being off-topic, unfocused, inappropriate, or spammy.

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [August 28, 2022, 2:03pm UTC](https://discourse.julialang.org/t/plot-exponential-fit/86455/6 "2022-08-28T14:03:40Z")

</div>

```julia
plot!(exp_fit; seriestype=:line, label="Exponential fit")

```

---

<div class="post-metadata">

**Author:** ![Mahmoud](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Mahmoud](https://discourse.julialang.org/u/Mahmoud)\
**Post date:** [August 31, 2022, 11:07am UTC](https://discourse.julialang.org/t/plot-exponential-fit/86455/7 "2022-08-31T11:07:33Z")

</div>

> [@Mahmoud](#):
>
> the second one is generated using python

p2=plot(dayss,numberofinfectedd,color =:green, xlabel=“Days”, ylabel=“Population”,label = “Infected”)

---

<div class="post-metadata">

**Author:** ![Mahmoud](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Mahmoud](https://discourse.julialang.org/u/Mahmoud)\
**Post date:** [August 31, 2022, 11:09am UTC](https://discourse.julialang.org/t/plot-exponential-fit/86455/8 "2022-08-31T11:09:05Z")

</div>

```julia
p2=plot(dayss,numberofinfectedd,color =:green, xlabel="Days", ylabel="Population",label = "Infected")

```

---

<div class="post-metadata">

**Author:** ![albheim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albheim/32/34660_2.png) [@albheim](https://discourse.julialang.org/u/albheim)\
**Post date:** [August 31, 2022, 2:17pm UTC](https://discourse.julialang.org/t/plot-exponential-fit/86455/9 "2022-08-31T14:17:21Z")

</div>

It is still a little unclear to me what you are asking for help with. But here is a way that might plot it similarly to what you are asking for

```julia
p2 = plot(dayss, numberofinfected, markershape=:rect, ylims=[1, 100], yscale=:log10, label="Infected", xlabel="Days", ylabel="Population", color=:green)
plot!(p2, expdays, expfit, linestyle=:dash, label="Exponential Fit", color=:green)

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [August 31, 2022, 2:30pm UTC](https://discourse.julialang.org/t/plot-exponential-fit/86455/10 "2022-08-31T14:30:04Z")

</div>

It seems unlikely that this is the whole Python code, as the Python version has two lines, one of which is labelled “Exponential Fit”, so that must come from somewhere.

I guess what people having been trying to tell you is that you are looking for something like this:

```julia
plot(days, infected, label = "Infected", linetype = :scatterpath)
plot!(days, exp_fit, label = "Exponential Fit", linetype = :dash)

```

so basically `plot(x, y)` plots a line, and `plot!(x, y)` adds another line to the same figure. What you need to provide is the x and y data, i.e. the days for the x data, and the data on infected and the exponential fit for the y data.

---

<div class="post-metadata">

**Author:** ![Mahmoud](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Mahmoud](https://discourse.julialang.org/u/Mahmoud)\
**Post date:** [August 31, 2022, 3:01pm UTC](https://discourse.julialang.org/t/plot-exponential-fit/86455/11 "2022-08-31T15:01:52Z")

</div>

> [@albheim](#):
>
> ```julia
> plot!(p2, expdays, expfit, linestyle=:dash, label="Exponential Fit", color=:green)
> 
> ```

Many thanks for you comment  
the python code is from a paper and I do not have access to the source code  
I am trying to reproduce the same results using julia  
It seems the same but I do not know how to represent it like original paper

---

<div class="post-metadata">

**Author:** ![Mahmoud](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Mahmoud](https://discourse.julialang.org/u/Mahmoud)\
**Post date:** [August 31, 2022, 3:03pm UTC](https://discourse.julialang.org/t/plot-exponential-fit/86455/12 "2022-08-31T15:03:31Z")

</div>

> [@nilshg](#):
>
> `exp_fit`

Where should I find “exp\_fit” ?

---

<div class="post-metadata">

**Author:** ![jacobusmmsmit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacobusmmsmit/32/217669_2.png) [@jacobusmmsmit](https://discourse.julialang.org/u/jacobusmmsmit)\
**Post date:** [August 31, 2022, 3:25pm UTC](https://discourse.julialang.org/t/plot-exponential-fit/86455/13 "2022-08-31T15:25:19Z")

</div>

This is a vector that you must make yourself in order be able to plot it. The replies are assuming that you have already done this. If you struggle with this and would like help please specify what sort of exponential fit is being produced and we can point you in the right direction.

---

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [August 31, 2022, 3:50pm UTC](https://discourse.julialang.org/t/plot-exponential-fit/86455/14 "2022-08-31T15:50:44Z")

</div>

You can try the [EasyFit](https://github.com/m3g/EasyFit.jl#example) package.

```julia
using EasyFit, Plots
exp_fit = fitexp(days[1:10], numberofinfected[1:10]) #Looks like you will need to slice the data to get the right fit
plot(days, infected, label = "Infected", linetype = :scatterpath)
plot!(exp_fit.x, exp_fit.y, label = "Exponential Fit", linetype = :dash)

```
