# Problem Using annotate! to add info to an animated plot but it overlaps and cannot be read

**URL:** <https://discourse.julialang.org/t/problem-using-annotate-to-add-info-to-an-animated-plot-but-it-overlaps-and-cannot-be-read/95935>\
**Category:** Visualization\
**Tags:** plotting, animate\
**Created:** [March 11, 2023, 8:08pm UTC](https://discourse.julialang.org/t/problem-using-annotate-to-add-info-to-an-animated-plot-but-it-overlaps-and-cannot-be-read/95935 "2023-03-11T20:08:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![J\_Braulio\_Ramz\_G](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_braulio_ramz_g/32/47609_2.png) [@J\_Braulio\_Ramz\_G](https://discourse.julialang.org/u/J_Braulio_Ramz_G)\
**Post date:** [March 11, 2023, 8:08pm UTC](https://discourse.julialang.org/t/problem-using-annotate-to-add-info-to-an-animated-plot-but-it-overlaps-and-cannot-be-read/95935/1 "2023-03-11T20:08:25Z")

</div>

Hi I am triying to use !annotate() to add text info like current iteration, aproximation and relative error to an animation of Newton-Raphson method but the previous info is accumulating in the new frames and overlaps. How can I avoid that to be able to see the info propperly?

> Blockquote

function animate\_newton\_raphson(df, f\_expr, vars\_vec, x0, xcoor, ycoor, ts\_flat, sympy\_expr)

```
# Create LaTeX string of sympy_expr
latex_expr = latexify(sympy_expr)
#x0i=convert(Float64,x0)
p = plot(f_expr, x0i:0.01:x0d, label="f(x)", color=:navy, title= " Newton-Raphson Method", grid= false)

for i in 1:size(df, 1)

    if i == 1
        scatter!(p, [x0[1]], [f_expr(x0[1])], markersize=4, markerstrokecolor=:black,markerstrokewidth=0.5, color=:red, label="", legend=:none)
        
    else
        scatter!(p, [df.vars[i]], [df.f_x[i]], markersize=4, markerstrokecolor=:black, markerstrokewidth=0.5, color=:green, label="", legend=:none)
        plot_lines_to_xaxis(xcoor, ycoor, ts_flat, p)
        
    end
    annotate!(x0d,5,text("$(LIteration) $(riterc[i])\n $(Lapprox) $(rxcoor[i])\n $(Lerror) $(rcrel_err[i])",
    halign=:right, valign=:bottom, pointsize=8))
   
end
return p

```

end

animation = @animate for i=1:size(df, 1)  
animate\_newton\_raphson(df[1:i, :], f\_expr, vars\_vec, x0, xcoor, ycoor, ts\_flat, sympy\_expr)  
end

gif(animation, “3N-R\_converg.gif”, fps=10)

![NR](https://global.discourse-cdn.com/julialang/original/3X/4/a/4aed9b64b53d281b689e56f82551aa013efa2d05.gif)

---

<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:** [March 11, 2023, 9:05pm UTC](https://discourse.julialang.org/t/problem-using-annotate-to-add-info-to-an-animated-plot-but-it-overlaps-and-cannot-be-read/95935/2 "2023-03-11T21:05:39Z")

</div>

Assuming you are using Plots.jl, you could try workaround as per this example:

```julia
using Printf, Plots; gr()

plot(cos, -5:0.1:5)
str0 = "█"^6
for i in 0:50:1000
    stri = @sprintf("Iteration: %5i", i)
    annotate!([5],[1], text(str0, :white, halign=:right))
    display(annotate!([5],[1], text(stri, halign=:right, pointsize=8)))
    sleep(0.1)
end

```
