\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}