我想将函数公式放在函数上方,如示例中所示。
我的代码:
\begin{tikzpicture}
\draw[style=help lines, dashdotted, gray, thick] (-2,4) grid (3,-2);
\tkzInit[xmax=4,ymax=4,xmin=-3,ymin=-2]
\tkzAxeXY
\draw[scale=1, domain=-1.2:2.2, smooth, variable=\x, blue] plot ({\x}, {-(\x*\x)+\x+2}) node [pos=0.6, above right, black] {$y=-x^2+x+2$};
\end{tikzpicture}
答案1
很简单,使用pstricks
:
\documentclass[svgnames, pstricks, border=10pt]{standalone}
\usepackage{pst-plot, multido}
\begin{document}
\begin{pspicture}(-2.5,-2.5)(4.5,4.5)
\psset{algebraic, plotpoints=100, showorigin=false, arrowinset=0.15, linejoin=1, gridcoor={(-1,-1)(3,3)}}
\multido{\i=-1+1}{5}{\psset{linewidth=0.5pt, linestyle=dashed, linecolor=Gainsboro}\psline(-2,\i)(3,\i)}
\multido{\i=-1+1}{4}{\psset{linewidth=0.5pt, linestyle=dashed, linecolor=Gainsboro}\psline(\i, -2)(\i,4)}
\psaxes[labelFontSize=\scriptstyle,ticksize=-2pt 2pt, linecolor=LightSteelBlue]{->}(0,0)(-2.5,-2.5)(4.5,4.5)[$x$,-120][$y$,210]
\psset{linewidth=1pt,algebraic, linecolor=IndianRed}
\psplot[linecolor=RoyalBlue] {-1.5}{2.5}{-x^2+x+2}
\uput{0.5em}[ur](0.5,2.25){$-x^2+x+2$}
\uput[dl](0,0){$\scriptstyle 0$}
\end{pspicture}
\end{document}
答案2
因此,我们承认您只想使用tkz-fct
网格和轴,并且不想安装gnuplot
(我同意)。因此,您可以在两个单独的命令中绘制曲线并放置方程式:
\documentclass{article}
\usepackage{tkz-fct}
\begin{document}
\begin{tikzpicture}[scale=1.25]
\tkzInit[xmin=-2,xmax=4,ymin=-2,ymax=4]
\tkzGrid
\tkzAxeXY
\clip (-2,-2) rectangle (4,4);
\draw[domain=-2:4, smooth, variable=\x, blue, thick] plot ({\x}, {-(\x*\x)+\x+2});
\node[right] at (0.5,2.5) {$y=-x^2+x+2$};
\end{tikzpicture}
\end{document}