# Create Tangent Line / Derivative Line Animation with Plots got Errors

**URL:** <https://discourse.julialang.org/t/create-tangent-line-derivative-line-animation-with-plots-got-errors/87814>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [September 26, 2022, 1:45pm UTC](https://discourse.julialang.org/t/create-tangent-line-derivative-line-animation-with-plots-got-errors/87814 "2022-09-26T13:45:26Z")\
**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:** [September 26, 2022, 1:45pm UTC](https://discourse.julialang.org/t/create-tangent-line-derivative-line-animation-with-plots-got-errors/87814/1 "2022-09-26T13:45:27Z")

</div>

Hi all,

Is it possible to create the animation of sliding tangent line with Plots?

I got error with my code:

```julia
using Plots 

f(x) = -x^2 + 2x + 2
gradient_line(f, x₀) = (x -> f(x₀) + f'(x₀)*(x-x₀))
plot(f, -3:0.1:5, label = "f(x) = -x² + 2x + 2", xlabel = "x", ylabel = "f(x)");

@gif for i in 1:3
    plot(gradient_line(f, i), -3:0.1:0.5, label = "f'($i)", color = 2);
end

```

**ERROR: LoadError: MethodError: no method matching adjoint(::typeof(f))**  
**Closest candidates are:**  
\*\* adjoint(::Union{LinearAlgebra.QR, LinearAlgebra.QRCompactWY, LinearAlgebra.QRPivoted}) at ~/julia-1.7.3/share/julia/stdlib/v1.7/LinearAlgebra/src/qr.jl:509\*\*  
\*\* adjoint(::Union{LinearAlgebra.Cholesky, LinearAlgebra.CholeskyPivoted}) at ~/julia-1.7.3/share/julia/stdlib/v1.7/LinearAlgebra/src/cholesky.jl:538\*\*  
\*\* adjoint(::LinearAlgebra.Hessenberg) at ~/julia-1.7.3/share/julia/stdlib/v1.7/LinearAlgebra/src/hessenberg.jl:423\*\*  
\*\* …\*\*  
**Stacktrace:**  
\*\* [1] (::var"#17#18"{typeof(f), Int64})(x::Float64)\*\*  
\*\* @ Main ~/LasthrimProjection/plot.jl:4\*\*  
\*\* [2] iterate\*\*  
\*\* @ ./generator.jl:47 [inlined]\*\*  
\*\* [3] \_collect\*\*  
\*\* @ ./array.jl:744 [inlined]\*\*  
\*\* [4] collect\_similar(cont::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, itr::Base.Generator{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, var"#17#18"{typeof(f), Int64}})\*\*  
\*\* @ Base ./array.jl:653\*\*  
\*\* [5] map(f::Function, A::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64})\*\*  
\*\* @ Base ./abstractarray.jl:2867\*\*  
\*\* [6] \_compute\_y\*\*  
\*\* @ ~/.julia/packages/RecipesPipeline/OXGmH/src/series.jl:72 [inlined]\*\*  
\*\* [7] \_compute\_xyz(x::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, y::Function, z::Nothing, nice\_error::Bool)\*\*  
\*\* @ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/series.jl:86\*\*  
\*\* [8] macro expansion\*\*  
\*\* @ ~/.julia/packages/RecipesPipeline/OXGmH/src/series.jl:147 [inlined]\*\*  
\*\* [9] apply\_recipe(plotattributes::AbstractDict{Symbol, Any}, #unused#::Type{RecipesPipeline.SliceIt}, x::Any, y::Any, z::Any)\*\*  
\*\* @ RecipesPipeline ~/.julia/packages/RecipesBase/qpxEX/src/RecipesBase.jl:289\*\*  
\*\* [10] \_process\_userrecipes!(plt::Any, plotattributes::Any, args::Any)\*\*  
\*\* @ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/user\_recipe.jl:36\*\*  
\*\* [11] recipe\_pipeline!(plt::Any, plotattributes::Any, args::Any)\*\*  
\*\* @ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/RecipesPipeline.jl:70\*\*  
\*\* [12] \_plot!(plt::Plots.Plot, plotattributes::Any, args::Any)\*\*  
\*\* @ Plots ~/.julia/packages/Plots/lW9ll/src/plot.jl:209\*\*  
\*\* [13] #plot#145\*\*  
\*\* @ ~/.julia/packages/Plots/lW9ll/src/plot.jl:91 [inlined]\*\*  
\*\* [14] macro expansion\*\*  
\*\* @ ~/LasthrimProjection/plot.jl:8 [inlined]\*\*  
\*\* [15] top-level scope\*\*  
\*\* @ ~/.julia/packages/Plots/lW9ll/src/animation.jl:235\*\*  
\*\* [16] include(fname::String)\*\*  
\*\* @ Base.MainInclude ./client.jl:451\*\*  
\*\* [17] top-level scope\*\*  
\*\* @ REPL[1]:1\*\*  
**in expression starting at /home/browni/LasthrimProjection/plot.jl:7**

![Capture d’écran_2022-09-26_20-43-42](https://global.discourse-cdn.com/julialang/original/3X/f/d/fdfb59e001bbe915eebfd5332836580b553d21cc.png)

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [September 26, 2022, 1:58pm UTC](https://discourse.julialang.org/t/create-tangent-line-derivative-line-animation-with-plots-got-errors/87814/2 "2022-09-26T13:58:22Z")

</div>

Did you forgot:

```julia
using Zygote

```

?

---

<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:** [September 28, 2022, 10:17am UTC](https://discourse.julialang.org/t/create-tangent-line-derivative-line-animation-with-plots-got-errors/87814/3 "2022-09-28T10:17:58Z")

</div>

Yes, I do not know that I need Zygote…

I am trying to make the animation correctly now…
