我正在使用pgfplots
和tikz
,下面是我现在拥有的代码。
\begin{tikzpicture}
\begin{axis}[
axis x line=middle,
axis y line=middle,
axis line style={=>},
xmin=-1,xmax=5,
ymin=-1,ymax=5,
xlabel=$x$,
ylabel=$y$,
xtick=\empty,
ytick=\empty,
xticklabels=\empty,
yticklabels=\empty,
]
\addplot[smooth,very thick,black,-]{-(x-(3/2))^2+(25/8)};
\draw (0,0) coordinate
\end{axis}
\end{tikzpicture}
标签的代码是什么:
- 以字母 O 为起源?
- x 截距 (4,0)
- 顶点在 x 轴和 y 轴上的 x 值和 y 值
- 通向顶点的虚线
- 抛物线顶部的标签 y=f(x)
底线:我正在尝试绘制一个与附图一模一样的图表。
谢谢。
答案1
钛钾Z 允许您在路径中声明函数并解析表达式,因此您可以执行以下操作:
\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}[declare function={f(\x)=-(\x-(3/2))^2+(25/8);}]
\begin{axis}[
axis x line=middle,
axis y line=middle,
axis line style={=>},
xmin=-1,xmax=5,
ymin=-1,ymax=5,
xlabel=$x$,
ylabel=$y$,
xtick=\empty,
ytick=\empty,
xticklabels=\empty,
yticklabels=\empty,
]
\addplot[smooth,very thick,black,-]{f(x)};
\path (0,0) node[below left]{$O$};
\draw[dashed] (0,{f(3/2)}) node[left]{$\frac{25}{8}$}-- (3/2,{f(3/2)})
node[above right]{$y=f(x)$} -- (3/2,0) node[below]{$\frac{3}{2}$};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
作为纯 TikZ 图片:
\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[declare function={f(\x)=-(\x-(3/2))^2+(25/8);}]
\draw[->] (-1,0) -- (4,0) node[below left] {$x$};
\draw[->] (0,-1) -- (0,4) node[below left] {$y$};
\draw[very thick]
plot[domain=-0.5:3.5, samples=100] (\x,{f(\x)});
\node[above right,inner sep=1pt] at (2,{f(2)}) {$y=f(x)$};
\node[below left, inner sep=1pt] at (0,0) {$O$};
\draw[dashed]
(0,{f(3/2)}) node[left] {$\frac{25}{8}$}
-| (3/2,0) node[below] {$\frac{ 3}{2}$};
\end{tikzpicture}
\end{document}