# Sequentially adding lines with plot! ending up in overwriting

**URL:** <https://discourse.julialang.org/t/sequentially-adding-lines-with-plot-ending-up-in-overwriting/122520>\
**Category:** General Usage\
**Tags:** plots\
**Created:** [November 12, 2024, 3:35am UTC](https://discourse.julialang.org/t/sequentially-adding-lines-with-plot-ending-up-in-overwriting/122520 "2024-11-12T03:35:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![miguelborrero](https://avatars.discourse-cdn.com/v4/letter/m/eb9ed0/32.png) [@miguelborrero](https://discourse.julialang.org/u/miguelborrero)\
**Post date:** [November 12, 2024, 3:35am UTC](https://discourse.julialang.org/t/sequentially-adding-lines-with-plot-ending-up-in-overwriting/122520/1 "2024-11-12T03:35:35Z")

</div>

Hi there, quick question: is there a reason why this function does not produce a single plot with the various lines desired? I get a plot with the last line only and my understanding is that this should not happen.

```julia
function plotting_estimated_F(
                              data,
                              set_n
                              )
    estimates = grid_estimation_F(data, set_n[1])
    plot(estimates[1], estimates[2], label = "Number bidders: $(set_n[1])")
    for n in set_n[2:end]
        estimates = grid_estimation_F(data, n)
        plot!(estimates[1], estimates[2], label = "Number bidders: $n")
    end
    plot!(xlabel = "\$v\$", ylabel = "\$\\hat{F}(v)\$", legend=:bottomright)
    plot!(guidefont = (8, "Computer Modern"), tickfont = (7, "Computer Modern"), titlefont = (7, "Computer Modern"), legendfont = (7, "Computer Modern"))
    savefig(figure_dir * "ECDF_F_ascending.pdf")
end

```

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [November 12, 2024, 6:22am UTC](https://discourse.julialang.org/t/sequentially-adding-lines-with-plot-ending-up-in-overwriting/122520/2 "2024-11-12T06:22:53Z")

</div>

Hi! Can you provide a full reproducible example, with all necessary imports and data definitions?

---

<div class="post-metadata">

**Author:** ![Andrew\_Swann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andrew_swann/32/32106_2.png) [@Andrew\_Swann](https://discourse.julialang.org/u/Andrew_Swann)\
**Post date:** [November 12, 2024, 2:20pm UTC](https://discourse.julialang.org/t/sequentially-adding-lines-with-plot-ending-up-in-overwriting/122520/3 "2024-11-12T14:20:29Z")

</div>

I think you need to name your plot, e.g. `p = plot(...)`, and then update it with `plot!(p,....)`
