代码如下:
\begin{figure}[H]
\centering
\begin{tikzpicture}[>=stealth',scale=1]
\tkzInit[xmin=-2,xmax=4,
ymin=0,ymax=10,
xstep=1,ystep=2]
\tkzAxeXY
\tkzFct[domain=-2:4,color=OliveGreen,very thick,-]{\x+4};
\draw [color=OliveGreen] (4.1,4.2) node {$r$};
\end{tikzpicture}
\caption{\small Gráfico de $f(x)=x+4$.}
\label{fig4.8}
\end{figure}
答案1
这是一个 TikZ 解决方案。
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}[yscale=.8]
\draw[violet!25] (-2.5,-.5) grid[ystep=2cm] (4.5,10.5);
\draw[-stealth] (-2.5,0)--(4.5,0) node[below]{$x$};
\draw[-stealth] (0,-1)--(0,10.5) node[right]{$y$};
\definecolor{OliveGreen}{RGB}{109,113,46}
\draw[OliveGreen,very thick] plot[domain=-2:4] (\x,{\x+4});
\foreach \i in {-2,-1,1,2,3,4}
\draw (\i,.2)--(\i,-.2) node[below,fill=white]{$\i$};
\foreach \j in {2,4,...,10}
\draw (.2,\j)--(-.2,\j) node[left=1mm,fill=white]{$\j$};
\path
(-2,2)--(4,8) node[OliveGreen,sloped,midway,below=1mm]{$f(x)=x+4$}
(current bounding box.south) node[below=2mm]{Gráfico de $f(x)=x+4$};
\end{tikzpicture}
\end{document}