# How to Plot inside For Loop for Differential Equation

**URL:** https://discourse.julialang.org/t/how-to-plot-inside-for-loop-for-differential-equation/88478
**Category:** General Usage
**Tags:** plotting
**Created:** [October 9, 2022, 2:05pm UTC](https://discourse.julialang.org/t/how-to-plot-inside-for-loop-for-differential-equation/88478 "2022-10-09T14:05:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)
#### Post date: [October 9, 2022, 2:05pm UTC](https://discourse.julialang.org/t/how-to-plot-inside-for-loop-for-differential-equation/88478/1 "2022-10-09T14:05:56Z")

</div>

Hi all,

I read this topic but it is not helping me to plot in a looping:

> <https://stackoverflow.com/questions/46141141/plots-jl-plots-inside-for-cycle>

I want to plot functions of:

p = 900 +e^{t/2}

p = 900 +50e^{t/2}

p = 900 +100e^{t/2}

p = 900 +150e^{t/2}

p = 900 +200e^{t/2}

p = 900 -50e^{t/2}

p = 900 -100e^{t/2}

p = 900 -150e^{t/2}

p = 900 -200e^{t/2}

it should be easy to use for loop (for i in 50:50:200), but why my code below does not work?

```julia
using Plots, LaTeXStrings, Plots.PlotMeasures
gr()

f(x) = 900 + exp(x/2)
   
plot(f,0,10, xticks=false, xlims=(0,10), ylims=(600,1200), 
    bottom_margin = 10mm, label=L" 900 + ce^{t/2}", framestyle = :zerolines, 
    legend=:outerright)

for i = 50:50:200
g(x) = 900 + i*exp(x/2) 
display(plot!(g, xticks=false, xlims=(0,10), ylims=(600,1200), 
    bottom_margin = 10mm, label="", framestyle = :zerolines, 
    legend=:outerright))    
end

```

It becomes 3 layouts, I just want 1 layout with multiple graphs.

---

<div class="post-metadata">

### Author: ![RayleighLord](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rayleighlord/32/33592_2.png) [@RayleighLord](https://discourse.julialang.org/u/RayleighLord)
#### Post date: [October 9, 2022, 2:30pm UTC](https://discourse.julialang.org/t/how-to-plot-inside-for-loop-for-differential-equation/88478/2 "2022-10-09T14:30:44Z")

</div>

Does this work for you?

```julia
using Plots, LaTeXStrings, Plots.PlotMeasures
gr()

f(x) = 900 + exp(x / 2)

p = plot(f, 0, 10, xticks=false, xlims=(0, 10), ylims=(600, 1200),
    bottom_margin=10mm, label=L" 900 + ce^{t/2}", framestyle=:zerolines,
    legend=:outerright)

for i = 50:50:200
    g(x) = 900 + i * exp(x / 2)
    plot!(p, g, xticks=false, xlims=(0, 10), ylims=(600, 1200),
        bottom_margin=10mm, label="", framestyle=:zerolines,
        legend=:outerright)
end

display(p)

```

---

<div class="post-metadata">

### Author: ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)
#### Post date: [October 9, 2022, 2:36pm UTC](https://discourse.julialang.org/t/how-to-plot-inside-for-loop-for-differential-equation/88478/3 "2022-10-09T14:36:35Z")

</div>

Works great,

it seems too many variables I made lots of mistakes then

```julia
using Plots, LaTeXStrings, Plots.PlotMeasures
gr()

f(x) = 900 + exp(x / 2)

p = plot(f, 0, 10, xticks=false, xlims=(0, 10), ylims=(600, 1200),
    bottom_margin=10mm, label=L" 900 + e^{t/2}", framestyle=:zerolines,
    legend=:outerright)

for i = 10:20:100
    g(x) = 900 + i * exp(x / 2)
    plot!(p, g, xticks=false, xlims=(0, 10), ylims=(600, 1200),
        bottom_margin=10mm, label="", framestyle=:zerolines,
        legend=:outerright)
end

for i = 10:20:100
    g(x) = 900 - i * exp(x / 2)
    plot!(p, g, xticks=false, xlims=(0, 10), ylims=(600, 1200),
        bottom_margin=10mm, label="", framestyle=:zerolines,
        legend=:outerright)
end

display(p)

```
