1

I have been stuck for a while with the curly brackets/braces problem in pgfplot.

I want the the curly brackets below the x-axis with some text (e.g. Part 1, Part 2 etc.):

enter image description here

I have no idea how to proceed further. The manual did not explain it clearly. Here a MWE:

\documentclass{report}
\usepackage{pgfplots}
\usepackage{float}
\usepackage{pgfkeys}
\usepackage{subcaption}
\pgfplotsset{compat=newest}
\usepackage{pgfmath} 
\pgfplotsset{plot coordinates/math parser=false}

\begin{document}
\begin{figure}[H]
\centering
\pgfplotstableread{
x         y    y-max  y-min

1           0.067783  0.02   0.02
2           0.066945  0.01   0.02
3           0.043508  0.02   0.02
4           0.043508  0.01   0.02
5       0.043508  0.01   0.02
6       0.043508  0.01   0.02
7       0.043508  0.02   0.02
8       0.043508  0.02   0.02
9       0.043508  0.01   0.01
10      0.043508  0.02   0.02
11      0.043508  0.01   0.01
12      0.043508  0.02   0.02
13      0.043508  0.01   0.01
14      0.043508  0.02   0.02
15      0.043508  0.01   0.01
16      0.043508  0.01   0.02
17      0.043508  0.02   0.01
18      0.043508  0.01   0.01
19          0.034655  0.02   0.02
20      0.051180  0.01   0.01
21      0.062882  0.02   0.02

}{\mytable}
\centering
\begin{tikzpicture}
\begin{axis}[
    height=65mm,
     width= \textwidth,
   ymin=0,
    ylabel={Value},
    xlabel= {Coordinate},
symbolic x coords={1,2,3, ,4,5,6,7,8,9,10,11,12,13,14,15, ,16,17,18,19,20,21},
xticklabels={23,24,25,6,7,8,9,11,12,13,14,15,16,26,27, 17,18,19,20,21,22},
       xtick=data,
       /pgf/number format/fixed, 
/pgf/number format/precision=2,
]
\addplot [only marks] 
  plot [error bars/.cd, y dir=both, y explicit, error bar style={line width=1pt},  error mark options={
      rotate=90,
      mark size=2pt,
      line width=1pt
    }]
  table [y error plus=y-max, y error minus=y-min] {\mytable};
\addplot[red, only marks, mark =diamond,  mark size=2.5, thick]
        coordinates {(1,0.0451648) (2,0.1095861) (3,0.1432419)    
          (4,0.1648329) (5,0.1649211051) (6,0.1517038807) (7,0.11349211051) (8,0.1249211051) (9,0.17549211051) (10,0.12949211051) (11,0.149211051) (12,0.16749211051) (13,0.19749211051) (14,0.1211051) (15,0.19211051) (16,0.13249211051) (17,0.16349211051) (18,0.19649211051) (19,0.10149211051) (20,0.12149211051) (21,0.134249211051) };  
 \addplot[blue, only marks, mark =star,  mark size=3, thick] 
                  coordinates {(1,0.051648) (2,0.095861) (3,0.132419)    
          (4,0.148329) (5,0.149211051) (6,0.117038807) (7,0.1349211051) (8,0.149211051) (9,0.1549211051) (10,0.1949211051) (11,0.19211051) (12,0.1649211051) (13,0.1749211051) (14,0.19211051) (15,0.149211051) (16,0.1249211051) (17,0.1349211051) (18,0.1649211051) (19,0.11049211051) (20,0.1149211051) (21,0.1249211051) };   
\end{axis} 
\end{tikzpicture}
\end{figure}
\end{document}
4

I used the xticklabel style key to name every x tick label node. The decoration library can draw braces instead of lines.

While there is a key for the amplitude, it is no easier to use than the macro.

\documentclass{report}
\usepackage{pgfplots}
\usetikzlibrary{decorations}
\usepackage{float}
\usepackage{pgfkeys}
\usepackage{subcaption}
\pgfplotsset{compat=newest}
\usepackage{pgfmath} 
\pgfplotsset{plot coordinates/math parser=false}

\begin{document}
\begin{figure}[H]
\centering
\pgfplotstableread{
x         y    y-max  y-min

1           0.067783  0.02   0.02
2           0.066945  0.01   0.02
3           0.043508  0.02   0.02
4           0.043508  0.01   0.02
5       0.043508  0.01   0.02
6       0.043508  0.01   0.02
7       0.043508  0.02   0.02
8       0.043508  0.02   0.02
9       0.043508  0.01   0.01
10      0.043508  0.02   0.02
11      0.043508  0.01   0.01
12      0.043508  0.02   0.02
13      0.043508  0.01   0.01
14      0.043508  0.02   0.02
15      0.043508  0.01   0.01
16      0.043508  0.01   0.02
17      0.043508  0.02   0.01
18      0.043508  0.01   0.01
19          0.034655  0.02   0.02
20      0.051180  0.01   0.01
21      0.062882  0.02   0.02

}{\mytable}
\centering
\begin{tikzpicture}
\begin{axis}[
    height=65mm,
     width= \textwidth,
   ymin=0,
    ylabel={Value},
    xlabel= {Coordinate},
    xlabel style={below=20pt},
symbolic x coords={1,2,3, ,4,5,6,7,8,9,10,11,12,13,14,15, ,16,17,18,19,20,21},
xticklabels={23,24,25,6,7,8,9,11,12,13,14,15,16,26,27, 17,18,19,20,21,22},
       xtick=data,
       /pgf/number format/fixed, 
/pgf/number format/precision=2,
xticklabel style={name=T\ticknum}% names every xtick label node T0,T1, ...
]
\addplot [only marks] 
  plot [error bars/.cd, y dir=both, y explicit, error bar style={line width=1pt},  error mark options={
      rotate=90,
      mark size=2pt,
      line width=1pt
    }]
  table [y error plus=y-max, y error minus=y-min] {\mytable};
\addplot[red, only marks, mark =diamond,  mark size=2.5, thick]
        coordinates {(1,0.0451648) (2,0.1095861) (3,0.1432419)    
          (4,0.1648329) (5,0.1649211051) (6,0.1517038807) (7,0.11349211051) (8,0.1249211051) (9,0.17549211051) (10,0.12949211051) (11,0.149211051) (12,0.16749211051) (13,0.19749211051) (14,0.1211051) (15,0.19211051) (16,0.13249211051) (17,0.16349211051) (18,0.19649211051) (19,0.10149211051) (20,0.12149211051) (21,0.134249211051) };  
 \addplot[blue, only marks, mark =star,  mark size=3, thick] 
                  coordinates {(1,0.051648) (2,0.095861) (3,0.132419)    
          (4,0.148329) (5,0.149211051) (6,0.117038807) (7,0.1349211051) (8,0.149211051) (9,0.1549211051) (10,0.1949211051) (11,0.19211051) (12,0.1649211051) (13,0.1749211051) (14,0.19211051) (15,0.149211051) (16,0.1249211051) (17,0.1349211051) (18,0.1649211051) (19,0.11049211051) (20,0.1149211051) (21,0.1249211051) };
\end{axis} 
\begin{scope}[decoration=brace]
  \pgfdecorationsegmentamplitude=5pt
  \draw[decorate] (T2.south east) -- (T0.south west) node[midway,below=\pgfdecorationsegmentamplitude] {Part 1};
  \draw[decorate] (T14.south east) -- (T3.south west) node[midway,below=\pgfdecorationsegmentamplitude] {Part 2};
  \draw[decorate] (T20.south east) -- (T15.south west) node[midway,below=\pgfdecorationsegmentamplitude] {Part 3};
\end{scope}
\end{tikzpicture}
\end{figure}
\end{document}

demo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.