# Is There Any Way to Plot Secant Line and Tangent Line given a point in a function?

**URL:** <https://discourse.julialang.org/t/is-there-any-way-to-plot-secant-line-and-tangent-line-given-a-point-in-a-function/87773>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [September 25, 2022, 9:02am UTC](https://discourse.julialang.org/t/is-there-any-way-to-plot-secant-line-and-tangent-line-given-a-point-in-a-function/87773 "2022-09-25T09:02:11Z")\
**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 25, 2022, 9:02am UTC](https://discourse.julialang.org/t/is-there-any-way-to-plot-secant-line-and-tangent-line-given-a-point-in-a-function/87773/1 "2022-09-25T09:02:11Z")

</div>

Hi all,

I wonder if there is any way to draw (automatically):

1. a secant line
2. a tangent line

with known function and a point at that function, is it possible?

I use pyplot backend, but I want to know other backend plotting / package that can plot them nicely. Or perhaps by using function is able too?

```julia
using Plots, LaTeXStrings
pyplot(fmt=:svg)

a, b = -3,3

h(x) = x^2

plot(h, a, b; legend=:outerright, label=L"\sin \frac{1}{x}", framestyle=:zerolines, 
	xlims = (-3,3), xticks = -3:1:3, 
	ylims = (-2,2), yticks = -2:1:2, 
	size=(720, 360))

```

![Capture d’écran_2022-09-25_15-57-58](https://global.discourse-cdn.com/julialang/original/3X/2/b/2b2a87303e5b1452fc2d63de012492a5ab26f791.png)

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [September 25, 2022, 1:46pm UTC](https://discourse.julialang.org/t/is-there-any-way-to-plot-secant-line-and-tangent-line-given-a-point-in-a-function/87773/2 "2022-09-25T13:46:33Z")

</div>

See my answer here:

> <https://stackoverflow.com/questions/66236968/plotting-a-line-tangent-to-a-function-at-a-point>

---

<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, 7:43am UTC](https://discourse.julialang.org/t/is-there-any-way-to-plot-secant-line-and-tangent-line-given-a-point-in-a-function/87773/3 "2022-09-26T07:43:43Z")

</div>

Thank you, it works well
