我正在尝试构建如下线图。我需要额外的空间来放置符号 x 轴,以便添加符号 $\tau=\bar{Y}{1,1}-\bar{Y}括号旁边有 {1,0}$。有什么办法吗?谢谢,
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines=left, ylabel={$BMI$}, ymax=90,ymin=30, xtick=\empty, ytick=\empty,
legend style={at={(0.5,0.2),anchor=north}
},
symbolic x coords={Baseline(T0), PostRandomization(T1)}, xtick=data]
\addplot[mark=diamond*,thick,red] coordinates {
(Baseline(T0),80) (PostRandomization(T1),70)};
\addlegendentry{Control}
\addplot[mark=o,mark options={solid},blue,thick,dashed] coordinates {
(Baseline(T0),79.5) (PostRandomization(T1),50) };
\addlegendentry{Treatment}
\draw [thick,decoration={brace,mirror,raise=5pt},decorate]
(axis cs:{PostRandomization(T1)},70) --
node[below=5pt]{$\tau=\bar{Y}_{1,1}-\bar{Y}_{1,0}$}
(axis cs:{PostRandomization(T1)},50);
\end{axis}
\end{tikzpicture}
\end{document}
答案1
我只需将支架放在轴的外侧和右侧即可。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines=left, ylabel={$BMI$}, ymax=90,ymin=30, xtick=\empty, ytick=\empty,
legend style={at={(0.5,0.2),anchor=north}
},
symbolic x coords={Baseline(T0), PostRandomization(T1)}, xtick=data]
\addplot[mark=diamond*,thick,red] coordinates {
(Baseline(T0),80) (PostRandomization(T1),70)};
\addlegendentry{Control}
\addplot[mark=o,mark options={solid},blue,thick,dashed] coordinates {
(Baseline(T0),79.5) (PostRandomization(T1),50) };
\addlegendentry{Treatment}
\path (axis cs:{PostRandomization(T1)},70) coordinate(p1)
(axis cs:{PostRandomization(T1)},50) coordinate(p2);
\end{axis}
\draw [thick,decoration={brace,raise=2pt},decorate]
(p1) --
node[right=3pt]{$\tau=\bar{Y}_{1,1}-\bar{Y}_{1,0}$}
(p2);
\end{tikzpicture}
\end{document}