3

I'm trying to draw brackets between data points with error bars to show significant differences.

Here's my current MWE:

Current MWE

\documentclass[letterpaper]{scrartcl}

\usepackage{tikz,pgfplots}

\begin{document}

\centering\begin{tikzpicture}[domain=0:1, scale=1] \begin{axis}[ymin=0, ymax=1, xmin=0, xmax=1, ytick={0,0.2,...,1}, ytick align=outside, ytick pos=left, xtick={0,0.2,...,1}, xtick align=outside, xtick pos=left, xlabel={$x$}, ylabel={$y$}, grid=major] \addplot+[ only marks, mark options={black, scale=1}, visualization depends on=\thisrow{alignment} \as \alignment, nodes near coords, point meta=explicit symbolic, every node near coord/.style={anchor=\alignment}, error bars/.cd, y fixed, y dir=both, y explicit, error bar style={width=4pt, line width=4pt, white!60!red} ] table [x=x, y=y,y error=error, col sep=comma, row sep=crcr, meta index=4] { name, x, y, error, label, alignment\ a, 0.1, 0.9, 0.03, $y_a$, 0 \ b, 0.2, 0.8, 0.08, $y_b$, -27 \ c, 0.5, 0.7, 0.12, $y_c$, 0 \ d, 1.0, 0.6, 0.15, $y_d$, -25 \ }; \end{axis} \end{tikzpicture}

\end{document}

Here's my desired outcome:

Desired outcome

I was hoping to reference the names of the nodes from the name column of the table to do something like this:

\draw [decorate,decoration={brace,amplitude=5pt,mirror,raise=6mm}]
(a.west) -- (b.east) node [black,midway, below, yshift=-10mm] {*};

This doesn't work; how do I reference the names correctly?

Here are a couple related questions that don't quite solve this:

Thanks!!

Lucas
  • 309

1 Answers1

1

I'll admit, my approach is rather clumsy. But it is also incredibly simple. If you scale correctly, you can use the grid lines as reference points and just fill in the line numbers. The axis being 0, 0.2=1, 0.4=2 and so forth …

This will be a great solution so long as you don't have to reference dozens or hundreds of points. For a small graphic it should suffice, though:

\documentclass{standalone}

\usepackage{tikz,pgfplots} \pgfplotsset{compat=1.16}

\begin{document}

\centering\begin{tikzpicture}[domain=0:1, scale=1] \begin{axis}[ymin=0, ymax=1, xmin=0, xmax=1, ytick={0,0.2,...,1}, ytick align=outside, ytick pos=left, xtick={0,0.2,...,1}, xtick align=outside, xtick pos=left, xlabel={$x$}, ylabel={$y$}, grid=major] \addplot+[ only marks, mark options={black, scale=1}, visualization depends on=\thisrow{alignment} \as \alignment, nodes near coords, point meta=explicit symbolic, every node near coord/.style={anchor=\alignment}, error bars/.cd, y fixed, y dir=both, y explicit, error bar style={width=4pt, line width=4pt, white!60!red} ] table [x=x, y=y,y error=error, col sep=comma, row sep=crcr, meta index=4] { name, x, y, error, label, alignment\ a, 0.1, 0.9, 0.03, $y_a$, 0 \ b, 0.2, 0.8, 0.08, $y_b$, -27 \ c, 0.5, 0.7, 0.12, $y_c$, 0 \ d, 1.0, 0.6, 0.15, $y_d$, -25 \ }; \end{axis} \draw [decorate,decoration={brace,mirror,raise=4ex},scale=1.37,blue,thick] (1,2.75) -- (2.5,2.75) node[midway,yshift=-2.5em]{$--$}; \draw [decorate,decoration={brace,mirror,raise=4ex},scale=1.37,blue,thick] (0.5,2) -- (1,2) node[midway,yshift=-2.5em]{$$}; \draw [decorate,decoration={brace,mirror,raise=4ex},scale=1.37,blue,thick] (1,2) -- (5,2) node[midway,yshift=-2.5em]{$$}; \draw [decorate,decoration={brace,mirror,raise=4ex},scale=1.37,blue,thick] (0.5,1.5) -- (2.5,1.5) node[midway,yshift=-2.5em]{$$}; \draw [decorate,decoration={brace,mirror,raise=4ex},scale=1.37,blue,thick] (2.5,1.5) -- (5,1.5) node[midway,yshift=-2.5em]{$--$}; \draw [decorate,decoration={brace,mirror,raise=4ex},scale=1.37,blue,thick] (0.5,1) -- (5,1) node[midway,yshift=-2.5em]{$*$}; \end{tikzpicture}

\end{document}

This is what you'll get:

line reference

phil-elkabat
  • 2,055