我正在尝试使用绘制一些数据pgfplots
,我目前有这个代码
\documentclass[12pt,article]{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=\linewidth,height=0.455\linewidth,
title={Values},
xlabel={Columns},
ylabel={Values},
xmin=0, xmax=12,
ymin=20000, ymax=30000,
xtick={1,2,3,4,5,6,7,8,9,10,11,12},
ytick={20000,25000,30000},
legend pos=north east,
ymajorgrids=true,
grid style=dashed,
]
\addplot[
color=blue,
mark=square,
]
coordinates {
(0,23599)(1,25533.5)(2,25543)(3,25549.5)(4,25551)(5,25561)(6,25717)(7,26188)(8,26245)(9,26650)(10,26923)(11,27495)(12,27603)
};
\addlegendentry{Example}
\end{axis}
\end{tikzpicture}
\end{document}
我怎样才能实现这个目标?
答案1
使用
xlabel style={yshift=-20pt},
我将 x 轴的标签向下移动以适应括号。
括号是使用brace
TikZdecorations.pathreplacing
库中的装饰获得的,并使用坐标系放置acis cs
;clip=false
添加了该选项。
代码:
\documentclass[12pt,article]{article}
\usepackage{pgfplots}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=\linewidth,height=0.455\linewidth,
title={Values},
xlabel style={yshift=-20pt},
xlabel={Columns},
ylabel={Values},
clip=false,
xmin=0, xmax=12,
ymin=20000, ymax=30000,
xtick={1,2,3,4,5,6,7,8,9,10,11,12},
ytick={20000,25000,30000},
legend pos=north east,
ymajorgrids=true,
grid style=dashed,
]
\addplot[
color=blue,
mark=square,
]
coordinates {
(0,23599)(1,25533.5)(2,25543)(3,25549.5)(4,25551)(5,25561)(6,25717)(7,26188)(8,26245)(9,26650)(10,26923)(11,27495)(12,27603)
};
\addlegendentry{Example}
\draw[decorate,decoration={brace,mirror}]
([yshift=-20pt]axis cs:0,20000) --
node[below=3pt] {$N_1$}
([yshift=-20pt]axis cs:5,20000);
\draw[decorate,decoration={brace,mirror}]
([yshift=-20pt]axis cs:6,20000) --
node[below=3pt] {$N_2$}
([yshift=-20pt]axis cs:12,20000);
\end{axis}
\end{tikzpicture}
\end{document}