\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{pgfplots}
\usepackage{xcolor}
\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
xlabel={x},
ylabel={y},
xmin=0, xmax=5,
ymin=0, ymax=8,
xtick={0,1,2,3,4,5},
ytick={0,2,4,6,8,10},
]
\addplot[
only marks,
color=blue,
mark=square
]
coordinates {
(1,2) (2,4) (3,4) (4,6)
};
\addplot[no marks,blue] expression[domain=1:4,samples=50]{1.6*x};
\end{axis}
\draw [decorate,decoration={brace,amplitude=2pt,mirror}, yshift = -0.2cm]
(2,4) -- (2,3.2) node (curly_bracket)[black,midway, yshift =- 0.3 cm]
{};
\end{tikzpicture}
\end{center}
\end{document}
我试图在点 (2,4) 和 (2,3.2) 之间绘制一个括号,但无法使用代码将其放在正确的位置
\draw [decorate,decoration={brace,amplitude=2pt,mirror}, yshift = -0.2cm]
(2,4) -- (2,3.2) node (curly_bracket)[black,midway, yshift =- 0.3 cm]
{};
。你可以理解括号表示当 x=2 时线的偏差。任何帮助都非常感谢!
谢谢!
答案1
尝试这个。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{pgfplots}
\usepackage{xcolor}
\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
xlabel={x},
ylabel={y},
xmin=0, xmax=5,
ymin=0, ymax=8,
xtick={0,1,2,3,4,5},
ytick={0,2,4,6,8,10},
]
\addplot[
only marks,
color=blue,
mark=square
]
coordinates {
(1,2) (2,4) (3,4) (4,6)
};
\addplot[no marks,blue] expression[domain=1:4,samples=50]{1.6*x};
\draw [decorate,decoration={brace,amplitude=2pt,mirror}, yshift = -0.2cm]
(axis cs:2,4) -- (axis cs:2,3.2) node (curly_bracket)[black,midway, yshift =- 0.3 cm]
{};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}