1

How to get the grouped labels with curly braces exactly in concurrence with the tikz axis, I could mange to align with arbitrarily value, is there any other way to align automatically?. For example, Task 1, Crew 1, the actual position is (0,0) to (3,0) but when drawn using the same, it does not produce the intended result, and hence draw, (0,0) to (4,0) to achieve the required result. Is there any automated procedure to fix this error, so that the arbitrary values may avoided.

enter image description here

\documentclass[12pt,border=10pt]{standalone}
\usepackage{tikz,pgf,pgfplots}
\usetikzlibrary{decorations.pathreplacing}
\pgfplotsset{compat=1.12} 
\begin{document}
\begin{tikzpicture}
\begin{axis}[title={},ylabel={\textbf{Task 2}},ymin=0,ymax=10,ytick={1, 2,...,10}, unbounded 
coords=jump, xmin=0,xmax=10,xtick={0,1,2,...,10},xlabel={\textbf{Task 1}},width=15.0cm,height=15.0cm,ylabel shift=0.75cm,xlabel shift=1.0cm,enlargelimits =false,grid,clip=false]
 \addplot+[thin,color=red,fill=red,mark=none]
 coordinates{
 (0,0)
 (3,0)
 (3,4)
 (0,4)
 (0,0)
 };
 \end{axis} 
 \draw [decorate,decoration={brace,amplitude=7pt,mirror,raise=4ex},thick]
 (0,0) -- (4,0) node[midway,yshift=-3em]{\textbf{Crew 1}};
 \draw [decorate,decoration={brace,amplitude=7pt,mirror,raise=4ex},thick]
 (4,0) -- (9.45,0) node[midway,yshift=-3em]{\textbf{Crew 2}};
 \draw [decorate,decoration={brace,amplitude=7pt,mirror,raise=4ex},thick]
  (9.45,0) -- (13.5,0) node[midway,yshift=-3em]{\textbf{Crew 3}};
  \draw [decorate,decoration={brace,amplitude=7pt,mirror,raise=4ex},thick,xshift=0.15em]
  (0,5.38) -- (0,0) node[midway,yshift=0em,xshift=-3em,rotate=90]{\textbf{Crew 1}};
  \end{tikzpicture}
  \end{document}
2

You can give the ticks names via alias, and use these nodes to have the precise positions to draw the braces from outside (without dropping clip etc). It also makes sense to use styles for the repeating set of keys used for the braces.

\documentclass[12pt,border=10pt]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{decorations.pathreplacing}
\pgfplotsset{compat=1.17} 
\begin{document}
\begin{tikzpicture}[mbrace/.style={decorate,decoration={brace,amplitude=7pt,mirror,raise=4ex},thick}]
\begin{axis}[title={},width=15.0cm,height=15.0cm,
    ylabel={\textbf{Task 2}},ymin=0,ymax=10,
    ytick={1, 2,...,10},yticklabel style={alias={ytick-\ticknum}}, 
    unbounded coords=jump, xmin=0,xmax=10,
    xtick={0,1,2,...,10},xticklabel style={alias={xtick-\ticknum}},
    xlabel={\textbf{Task 1}},ylabel shift=0.75cm,xlabel shift=1.0cm,
    enlargelimits =false,grid,clip=false]
 \addplot+[thin,color=red,fill=red,mark=none]
 coordinates{
 (0,0)
 (3,0)
 (3,4)
 (0,4)
 (0,0)
 };
 \end{axis} 
 \path (0,0) coordinate (P);
 \draw [mbrace] (xtick-0|-P) -- (xtick-3|-P) 
    node[midway,yshift=-3em,font=\bfseries]{Crew 1};
 \draw [mbrace] (xtick-3|-P) -- (xtick-6|-P) 
    node[midway,yshift=-3em,font=\bfseries]{Crew 2};
 \draw [mbrace] (xtick-6|-P) --(xtick-9|-P) 
    node[midway,yshift=-3em,font=\bfseries]{Crew 3};
 \draw [mbrace]  (ytick-3-|P) -- (current axis.south-|P) 
    node[midway,yshift=0em,xshift=-3em,rotate=90,font=\bfseries]{Crew 1};
\end{tikzpicture}
\end{document}

enter image description here

Some users prefer calligraphic braces.

\documentclass[12pt,border=10pt]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{decorations.pathreplacing,calligraphy}
\pgfplotsset{compat=1.17} 
\begin{document}
\begin{tikzpicture}[mbrace/.style={decorate,decoration={calligraphic brace,amplitude=7pt,mirror,raise=4ex},thick}]
\begin{axis}[title={},width=15.0cm,height=15.0cm,
    ylabel={\textbf{Task 2}},ymin=0,ymax=10,
    ytick={1, 2,...,10},yticklabel style={alias={ytick-\ticknum}}, 
    unbounded coords=jump, xmin=0,xmax=10,
    xtick={0,1,2,...,10},xticklabel style={alias={xtick-\ticknum}},
    xlabel={\textbf{Task 1}},ylabel shift=0.75cm,xlabel shift=1.0cm,
    enlargelimits =false,grid,clip=false]
 \addplot+[thin,color=red,fill=red,mark=none]
 coordinates{
 (0,0)
 (3,0)
 (3,4)
 (0,4)
 (0,0)
 };
 \end{axis} 
 \path (0,0) coordinate (P);
 \draw [mbrace] (xtick-0|-P) -- (xtick-3|-P) 
    node[midway,yshift=-3em,font=\bfseries]{Crew 1};
 \draw [mbrace] (xtick-3|-P) -- (xtick-6|-P) 
    node[midway,yshift=-3em,font=\bfseries]{Crew 2};
 \draw [mbrace] (xtick-6|-P) --(xtick-9|-P) 
    node[midway,yshift=-3em,font=\bfseries]{Crew 3};
 \draw [mbrace]  (ytick-3-|P) -- (current axis.south-|P) 
    node[midway,yshift=0em,xshift=-3em,rotate=90,font=\bfseries]{Crew 1};
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |
  • Schrödinger's cat, this works perfect. Thank you very much for your kindness and support. – rakatex May 12 at 16:39
  • 1
    @RameshKannan You are welcome! – user194703 May 12 at 16:41
2

If you want to use the axis cs for the braces, draw them inside the axis environment:

\documentclass[12pt,border=10pt]{standalone}
\usepackage{pgfplots}% loads tikz, pgf, ...
\usetikzlibrary{decorations.pathreplacing}
\pgfplotsset{compat=1.12}% current version would be 1.17
\begin{document}
\begin{tikzpicture}
  \begin{axis}[title={},ylabel={\textbf{Task 2}},ymin=0,ymax=10,ytick={1, 2,...,10}, unbounded 
coords=jump, xmin=0,xmax=10,xtick={0,1,2,...,10},xlabel={\textbf{Task 1}},width=15.0cm,height=15.0cm,ylabel shift=0.75cm,xlabel shift=1.0cm,enlargelimits =false,grid,clip=false]
    \addplot+[thin,color=red,fill=red,mark=none]
      coordinates{ (0,0) (3,0) (3,4) (0,4) (0,0) };
    \draw [decorate,decoration={brace,amplitude=7pt,mirror,raise=4ex},thick]
      (0,0) -- (3,0) node[midway,yshift=-3em]{\textbf{Crew 1}};
    \draw [decorate,decoration={brace,amplitude=7pt,mirror,raise=4ex},thick]
      (3,0) -- (7,0) node[midway,yshift=-3em]{\textbf{Crew 2}};
    \draw [decorate,decoration={brace,amplitude=7pt,mirror,raise=4ex},thick]
      (7,0) -- (10,0) node[midway,yshift=-3em]{\textbf{Crew 3}};
    \draw [decorate,decoration={brace,amplitude=7pt,mirror,raise=4ex},thick,xshift=0.15em]
      (0,4) -- (0,0) node[midway,xshift=-3em,rotate=90]{\textbf{Crew 1}};
  \end{axis}% <- moved
\end{tikzpicture}
\end{document}
| improve this answer | |
  • thank for your suggestion. It works perfectly good. – rakatex May 12 at 16:43

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.