答案1
带软件包的版本tzplot(链接至 CTAN), 基于蒂克兹(但根据包作者的说法,语法有所缩短):
\documentclass[11pt]{article}
\usepackage{tzplot}
\begin{document}
\begin{tikzpicture}
\tzfn[blue,thick]{(\x)^2-2}[-2.6:2.6]
\tzfn[red,thick]{\x}[-5:5]
\tzshoworigin*{0}[al](0pt)
\tzaxes[-](-5,-5)(5,5)
\tzticks*(-2pt:0pt){-5,...,5}(-2pt:0pt){-5,...,5}
\tzticksx(-4pt:0pt){-4,-2,2,4}[b=5pt]
\tzticksy(-4pt:0pt){-4,-2,2,4}[l=3pt]
\tznode(5,0){$x$}[b=5pt]
\end{tikzpicture}
\end{document}
笔记: \tzshoworigin[al]
不要显示“原产地”A博韦升eft”(错误?),但是在“左下角”,所以我需要使用带星号的语法,默认情况下不显示任何文本但是显示一个点,所以我用 指定文本{0}
,并指定点的大小(用(0pt)
隐藏它)。
答案2
像这样:
代码:
\documentclass[10pt,a4paper]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=1]
\draw[step=2,gray!20] (-4,-4) grid (4,4); % comment if grid is not desired
\draw[line width=1pt] (-4,0)--(4,0);
\foreach \x in {-4,-2,...,4} \draw (\x,0)--(\x,-0.1) node[below] {\footnotesize $\x$};
\draw[line width=1pt] (0,-4)--(0,4);
\clip (-4,-4) rectangle (4,4);
\foreach \x in {-4,-2,...,4} \draw (0,\x)--(-0.1,\x) node[left] {\footnotesize $\x$};
\draw[line width=2pt] plot[smooth] (\x,\x*\x-2);
\draw[line width=2pt,red] plot (\x,\x);
\end{tikzpicture}
\end{document}