Sequentially adding lines with plot! ending up in overwriting

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.

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!

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

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

1 Like