![如何使用 tkz-euclide 绘制二次函数?](https://linux22.com/image/349130/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%20tkz-euclide%20%E7%BB%98%E5%88%B6%E4%BA%8C%E6%AC%A1%E5%87%BD%E6%95%B0%EF%BC%9F.png)
答案1
使用tkz-fct
软件包,使用\tkzFct[<options>]{<function>}
,--shell-escape
启用后进行编译,我相信您需要已经gnuplot
安装。
\documentclass[border=5mm]{standalone}
\usepackage{tkz-fct}
\begin{document}
\begin{tikzpicture}[scale = 0.5]
\tkzInit[xmax=5,ymax=5,xmin=-5,ymin=-5]
\tkzGrid
\tkzLabelX[orig=true,label options={font=\tiny}]
\tkzLabelY[orig=false,label options={font=\tiny}]
\tkzDrawX
\tkzDrawY
\tkzFct[domain=-5:0,black]{\x**2-4}
\tkzFct[domain=0:5,black]{2*\x-4}
\end{tikzpicture}
\end{document}
如果您想要一种不涉及gnuplot
和的方法shell-escape
,您可以尝试pgfplots
:
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}[scale = 0.5]
\begin{axis}[
xmin=-5.5,xmax=5.5,
ymin=-5.5,ymax=5.5,
axis lines=center,
xlabel=$x$,
ylabel=$y$,
grid,
xtick={-5,...,5},
ytick={-5,...,5},
ticklabel style={font=\tiny,fill=white}]
\addplot [black,domain=-5:0] {x^2-4};
\addplot [black,domain=0:5] {2*x-4};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
谢谢,@Torbjørn T. 我想我刚刚通过使用\draw
\documentclass[border=5mm]{standalone}
\usepackage{tkz-fct}
\usepackage{tkz-euclide}
\usepackage{graphicx}
\usepackage{tkz-fct}
\begin{document}
\begin{tikzpicture}[scale = 0.5]
\tkzInit[xmax=5,ymax=5,xmin=-5,ymin=-5]
\tkzGrid
\tkzLabelX[orig=true,label options={font=\tiny}]
\tkzLabelY[orig=false,label options={font=\tiny}]
\tkzDrawX
\tkzDrawY
\draw[scale=1, domain=-3:0,smooth,variable=\x,blue, line width = 1pt] plot ({\x},{\x*\x-4});
\draw[scale=1, domain=0:4.5, smooth, variable=\x, blue, line width = 1pt] plot({\x}, {2*\x-4});
\end{tikzpicture}
\end{document}