有人能否帮助我提供一个最基本、最简单的代码来绘制抛物线“3x^2-x-4”,显示所有网格线、对称轴、根,并借助箭头、虚线和适当的坐标标记顶点。我只能绘制网格线,所有内联可用的东西都太复杂了。请帮忙。
答案1
只是为了好玩,一个简短的代码pstricks
:
\documentclass[x11names, svgnames, border=6pt]{standalone}
\usepackage{fourier}
\usepackage{pst-plot}
\usepackage{auto-pst-pdf}
\begin{document}
\psset{algebraic, xunit=2, yunit=1.5, arrowinset=0.12, arrowsize=4pt, linejoin=1, plotstyle=curve, plotpoints=200}%
\newpsstyle{gridstyleA}{gridlabels=0pt, gridcolor=LightSteelBlue, subgridcolor =LightSteelBlue!60, gridwidth=0.4pt, subgridwidth=0.4pt, subgriddiv=5, subgriddots=10}
\begin{pspicture*}[showgrid](-2.99, -4.8)(3, 4.8)
\psaxes[linecolor=SteelBlue, arrows=->, showorigin=false, tickcolor=black, xlabelPos=dr](0,0)(-2.8, -4.8)(2.8, 4.8)[$x$,-135] [$y$,-135]
\uput[dl](0,0){$O$}
\psset{linewidth=1.2pt, linecolor=IndianRed3}
\psplot{-5}{5}{3*x^2-x-4}
\psset{linecolor=black, linewidth=0.6pt}
\psCoordinates[linestyle=dashed](*0.167 {3*x^2-x-4})
\psline{<->}(-0.833, -4.083)(1.167, -4.083)
\end{pspicture*}
\end{document}
答案2
像这样:
使用几乎最少的Tikz
代码:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=1.5]
\draw[gray!20] (-4,-5) grid (4,4);
\draw[-latex] (-4,0)--(4,0) node[right] () {$x$};
\draw[-latex] (0,-5)--(0,4) node[above] () {$y$};
\foreach \x in {-4,-3,-2,-1,1,2,3,4} \draw (\x,.1)--(\x,-.1) node[below] () {\small \bfseries \x};
\foreach \y in {-5,-4,-3,-2,-1,1,2,3,4} \draw (.1,\y)--(-.1,\y) node[left] () {\small \bfseries \y};
\node () at (-.2,-.2) {$O$};
\clip (-4,-5) rectangle (4,4);
\draw[line width=3pt,cyan] plot[domain=-4:4,smooth] (\x,{3*\x*\x-\x-4});
\draw[dashed,line width=1pt] (1/6,-5)--(1/6,6);
\draw[<->,line width=1pt] (1/6-1,-49/12)--(1/6+1,-49/12);
\end{tikzpicture}
\end{document}