Runaway argument in beamer slide

Im trying to make a graphic using beamer that shows a function, his derivative and the normal vector in a point to the function, but Im unable to compile, it says

Runaway argument?
\par \draw [line width=1.2pt,color=blue!50!black,smooth,samples=100,\ETC.
! File ended while scanning use of \frame.
<inserted text>
\par


Im aware this errors are related to leaving something bad matched (a begin without end), but Im not finding anything like these and the options in the draw command does not seem odd to me.

The MWE (supposed to be) is:

\documentclass[spanish]{beamer}
\pgfplotsset{compat=1.17}
\usepackage{soul}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{tikz, xcolor}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{patterns,hobby}
\begin{document}
\begin{frame}

Sea una curva $C$ de ecuación $y=f(x)$ donde $f(x)$es continua

La pendiente de la recta tangente a la curva $C$en el punto $P(x_{0},y_{0}$)
es $m=f\prime(x_{0})$.
Usando la ecuación punto-pendiente de la recta:
\begin{center}
$y-y_{0}=m(x-x_{0})$
\end{center}
\begin{center}
$y-y_{0}=f\prime(x_{0})(x-x_{0})$
\end{center}
donde $x_{0}$ y $y_{0}$ son las coordenadas del punto de tangencia

\begin{tikzpicture}[scale=1]

\draw (-1,0) -- (7.5,0) (0,-.5) -- (0,4.5);
\node[below left=2pt and 2pt] at (0,0) {$O$};

\begin{scope}
\clip (-1,0) rectangle (7.5,4.5);
\draw[line width=1.2pt,color=red,smooth,samples=100,domain=-2.5:7.5] plot(\x,{0.3*((\x)-3.5)*((\x)-3.5)+0.5});
\end{scope}

\def\xA{2.5} \def\yA{0.8}
\coordinate (A) at (\xA,\yA);
\draw[dashed] (\xA,0) node[below=2pt] {$x_{0}$} -- (A) -- (0,\yA) node[left] {$y_{0}$};

\def\xM{6.5} \def\yM{3.2}
\coordinate (M) at (\xM,\yM);
\draw[dashed] (\xM,0) node[below] {$x_{0}+\Delta x$} -- (M) -- (0,\yM) node[left] {$y_{0}+\Delta x)$};
\begin{scope}
\clip (0.5,-0.5) rectangle (7.5,4.5);

\foreach \xN/\yN in {5}
{
\coordinate (N) at (\xN,\yN);
\tkzDrawPoint[size=8](N)
\tkzLabelPoint[line width=1.2pt,color=green!50!black,smooth,samples=100,domain=0.5:5](3,3){Rectas secantes}
}
\end{scope}

\draw[line width=1.2pt,color=blue!50!black,smooth,samples=100,domain=0.5:5] plot(\x,{-0.6*(\x)+2.3}) node[below] {Recta tangente a la curva en $P$};

\tkzDrawPoints[size=8](A,M)
\tkzLabelPoint[above=3pt](A){$P$}
\tkzLabelPoint[above left](M){$Q$}

\end{tikzpicture}
\end{frame}

\end{document}


When it is compiled without the frame environment it gets the next slide

UPDATE
After defining the \pgfplotsset and the proper libraries the MWE is

\documentclass[spanish]{beamer}
\usepackage[T1]{fontenc}
\usepackage[latin9]{luainputenc}
\usepackage{xcolor}
\usepackage{calc}
\usepackage{amsmath}
\PassOptionsToPackage{normalem}{ulem}
\usepackage{ulem}
\usepackage{subcaption}
\usepackage{pifont}
\usepackage{pgfplots}
\usepackage{tkz-euclide}
\usetikzlibrary{angles, quotes}
\usepackage{amsmath}
\usepackage{setspace}
\usepackage{amsthm}
\usetikzlibrary{decorations.markings}
\usepackage[makeroom]{cancel}
\usetikzlibrary{datavisualization.formats.functions}
\usepackage{pgfplotstable}
\usepackage{wasysym}
\usetikzlibrary{decorations.pathreplacing}
\pgfplotsset{compat=1.17}
\usepackage{soul}
\usepackage{amssymb}
\usepackage{enumitem}
\usepackage{pifont}
\usetikzlibrary{3d}
\usepackage{tikz, xcolor}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{patterns,hobby}

\begin{document}
\begin{frame}

Sea una curva $C$ de ecuación $y=f(x)$ donde $f(x)$es continua

La pendiente de la recta tangente a la curva $C$en el punto $P(x_{0},y_{0}$)
es $m=f\prime(x_{0})$.
Usando la ecuación punto-pendiente de la recta:
\begin{center}
$y-y_{0}=m(x-x_{0})$
\end{center}
\begin{center}
$y-y_{0}=f\prime(x_{0})(x-x_{0})$
\end{center}
donde $x_{0}$ y $y_{0}$ son las coordenadas del punto de tangencia

\begin{tikzpicture}[scale=1]

\draw (-1,0) -- (7.5,0) (0,-.5) -- (0,4.5); % Axis
\node[below left=2pt and 2pt] at (0,0) {$O$}; % Origin

\begin{scope}
\clip (-1,0) rectangle (7.5,4.5);
\draw[line width=1.2pt,color=red,smooth,samples=100,domain=-2.5:7.5] plot(\x,{0.3*((\x)-3.5)*((\x)-3.5)+0.5});
\end{scope}

\def\xA{2.5} \def\yA{0.8}
\coordinate (A) at (\xA,\yA);
\draw[dashed] (\xA,0) node[below=2pt] {$x_{0}$} -- (A) -- (0,\yA) node[left] {$y_{0}$};

\def\xM{6.5} \def\yM{3.2}
\coordinate (M) at (\xM,\yM);
\draw[dashed] (\xM,0) node[below] {$x_{0}+\Delta x$} -- (M) -- (0,\yM) node[left] {$y_{0}+\Delta x)$};
\begin{scope}
\clip (0.5,-0.5) rectangle (7.5,4.5);

\foreach \xN/\yN in {5}
{
\coordinate (N) at (\xN,\yN);
\tkzDrawPoint[size=8](N)
\tkzLabelPoint[line width=1.2pt,color=green!50!black,smooth,samples=100,domain=0.5:5](3,3){Rectas secantes}
}
\end{scope}

\draw[line width=1.2pt,color=blue!50!black,smooth,samples=100,domain=0.5:5] plot(\x,{-0.6*(\x)+2.3}) node[below] {Recta tangente a la curva en $P$};

\tkzDrawPoints[size=8](A,M)
\tkzLabelPoint[above=3pt](A){$P$}
\tkzLabelPoint[above left](M){$Q$}

\end{tikzpicture}
\end{frame}

\end{document}

• You didn't properly test your example: It errors because \pgfplotsset is not defined and \usepackage{tkz-euclide} is missing. If I remove the first and add the second it compiles fine for. Commented Jan 21, 2021 at 8:07
• I have added the euclide pack and set the pgfplotset from 1.1.4 to 1.17 and still not works, also I have checked for open {}[] or other symbols and I havent found why. Commented Jan 21, 2021 at 19:15
• \pgfplotsset can not work as you are not loading pgfplots. Provide an example that shows your error and not some other error first. Commented Jan 21, 2021 at 19:18

Edit (1): To provide solution is in Appendix frames added tangent calculation procedure for given function f(x).

Edit (2): It seems that the provided image of desired result has an error: secant should go through points P and Q (that it with becomes tangent). With this correction of the MWE presentation of tangent calculation become correct and its code a wee bit simpler.

Formating of the diagram is a wee bet modified. For it is used only pfplots package, tangent is calculated from derivative of function (see Appendix in MWE), for system of equation defining rules for calculation of tangent is used align environment defined in the amsmath package (loaded by beamer):

\documentclass[spanish]{beamer}
\setbeamertemplate{frametitle continuation}{\hfill%
(\insertcontinuationcount)}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usepackage[low-sup]{subdepth}

\begin{document}
\begin{frame}[fragile]

Sea una curva $C$ de ecuación $y=f(x)$ donde $f(x)$ es continua

La pendiente de la recta tangente a la curva $C$en el punto $P(x_{0},y_{0})$ es $m=f'(x_{0})$. Usando la ecuación punto-pendiente de la recta:
\begin{align*}
y-y_{0}    & = m(x-x_{0})                  \\
y-y_{0}    & = f'(x_{0})(x-x_{0})
\end{align*}
donde $x_{0}$ y $y_{0}$ son las coordenadas del punto de tangencia:
\begin{center}
\begin{tikzpicture}[
dot/.style = {circle, fill, inner sep=2pt,
fill opacity=0.5, text opacity=1,
label={[inner sep=1pt]#1}, node contents={}},
every node/.append style = {sloped, align=center,
font=\scriptsize, text depth=0.25ex},
]
\begin{axis}[width=90mm, height=60mm,
axis lines=middle,
ylabel=y,
ylabel style = {rotate=270},
xlabel=x,
ymin=-1.1,  ymax=5.0,   ytick=\empty,
xmin=-1.5,  xmax=7.5,   xtick=\empty,
no marks
]
\node[below left] at (0,0) {0}; % Origin
%
plot {0.3*(\x-3.5)^2 + 0.5};
% tangent
\draw[red,  shorten <=-2mm,  shorten >=-9mm ]
(0,2.975) -- (3.3,0)
node[at end] {Recta tangente\\ a la curva en $P$};
% P and Q coordinates
\draw[densely dashed]
( 2.0,-0.10)  node[below] {$x_0$} |-
(-0.1,1.175)  node[left]  {$y_0$}
node (p) [pos=0.5, dot=$P$];
\draw[densely dashed]
(6.5,-0.1) node[below] {$x_0+\Delta x$} |-
(-0.1,3.2) node[left]  {$y_0+\Delta y$}
node (q) [pos=0.5, dot=$Q$];
% secant
\draw[purple, shorten <=-12mm, shorten >=-9mm]
(p) --  node {Rectas\\ secantes}  (q);
\end{axis}
\end{tikzpicture}
\end{center}
\end{frame}

\begin{frame}[fragile, allowframebreaks]
\frametitle{Appendix:\\
calculation of the $f(x)$ tangent at the point $P(x_0,y_0)$}
\small

Rule (again):
{\color{blue}
\begin{align*}
y-y_{0}    & = m(x-x_{0})                  \\
y-y_{0}    & = f'(x_{0})(x-x_{0})
\end{align*}
}
Graph $p(x)$ at point $P(x_0=2,y)$:
\begin{align*}
f(x)    & = 0.3(x-3.5)^2 + 0.5  \\
P(2)    & = 0.3(2-3.5)^2 + 0.5 = 0.3(-1.5)^2 + 0.5 = \boxed{1.175}
\end{align*}

\begin{flalign*}
\text{Point $P$:}
&& P(2,y) & = P\bigl(2,p(2)\bigr) = (2,0.3(2-3.5)+0.5) && \\
&&        & = \boxed{$P(2,1.175)$}    &&
\end{flalign*}
Derivative of $f(x)$:
\begin{align*}
f'(x)   & = 0.3.2(x-3.5)^1 = 0.6x - 2.1 \\
f'(2)   & = 1.2 - 2.1 = \boxed{-0.9}
\end{align*}

\framebreak
Tangent:
\begin{align*}
y - 1.175
& = f'(2)(x - 2)    \Rightarrow     y = -0.9(x - 2) = -0.9x +1.8    \\
y   & = -0.9x + 1.8 + 1.175     \\
& = \boxed{-0.9x + 2.75}
\end{align*}
\begin{align*}
\text{value $y$ at $x=0$:} && y & = 2.975 \\
\text{value $x$ at $y=0$:} && x & = \frac{2.975}{0.9} = 3.305^\cdot
\end{align*}

\begin{center}
\begin{tikzpicture}[
dot/.style = {circle, fill, inner sep=2pt,
fill opacity=0.5, text opacity=1,
label={[inner sep=1pt]#1}, node contents={}},
every node/.append style = {sloped, font=\scriptsize, align=center},
every pin/.style = {pin edge={<-}, inner sep=1pt,
pin distance=3mm, font=\tiny}
]
\begin{axis}[width=90mm, height=45mm,
axis lines=middle,
ylabel=y,
ylabel style = {rotate=270},
xlabel=x,
ymin=-1.5,  ymax=5.5,   ytick=\empty,
xmin=-2.0,  xmax=7.5,   xtick=\empty,
no marks
]
\node[below left] at (0,0) {0}; % Origin

plot {0.3*(\x-3.5)^2 + 0.5};
% tangent
\draw[red,  shorten <=-2mm,  shorten >=-9mm ]
(0,2.975) coordinate (a) --
(3.3,0)   coordinate (b)
node[at end] {Recta tangente\\ a la curva en $P$};
\path   (a) node[inner sep=0pt, pin=225:2.975]{}
(b) node[inner sep=0pt, pin=265:$3.305^\cdot$] {};
% P and Q coordinates
\draw[densely dashed]
( 2.0,-0.10)  node[below] {$x_0=2$} |-
(-0.1,1.175)  node[left]  {$y_0$=1.175}
node (p) [pos=0.5, dot=$P$];
\draw[densely dashed]
(6.5,-0.1) node[below] {$x_0+\Delta x$} |-
(-0.1,3.2) node[left]  {$y_0+\Delta y$}
node (q) [pos=0.5, dot=$Q$];
% secant
\draw[purple, shorten <=-12mm, shorten >=-9mm]
(p) --  node {Rectas\\ secantes}  (q);
\end{axis}
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}


(frames with Appendix are not shown)

• @riccs_0x, see second edit of answer. Now the image is correct. Compiling MWE will give two more frames, where is present the procedure of tangent calculation. It may help some one. Commented Jan 23, 2021 at 23:18