5

I have the given bar plot with three hirachies (color + inner-group + outer-group):

Original image

The figure look overloaded but I don't know how to split the x axis labels in a better way. A possible solution could be this sketch:

Possible modification

Since I did not figure out a good workflow for me yet, the minimal example is still somewhat cluttered. I used matlab2tikz as a start and did some tikzmodifications by hand afterwards:

\documentclass{scrartcl}
\usepackage{pgfplots} % Import der Plots aus Matlab
\usepackage{tikz} % Import der Plots aus Matlab
\newlength{\fheight}
\newlength{\fwidth}
\pgfplotsset{compat=1.3}


\usepackage{amsmath,amsthm, amssymb, latexsym}

\begin{document}
\setlength\fheight{0.2\columnwidth}
\setlength\fwidth{0.42\columnwidth}

\definecolor{mycolor1}{rgb}{0.00000,0.00000,0.56250}%
\definecolor{mycolor2}{rgb}{0.00000,0.18750,1.00000}%
\definecolor{mycolor3}{rgb}{0.00000,0.87500,1.00000}%
\definecolor{mycolor4}{rgb}{0.56250,1.00000,0.43750}%
\definecolor{mycolor5}{rgb}{1.00000,0.81250,0.00000}%
% 
\begin{tikzpicture}[baseline, trim axis left, trim axis right]
  \newlength{\myBarWidth}
  \setlength{\myBarWidth}{0.011\fwidth}
  \newlength{\myBarShift}
  \setlength{\myBarShift}{0.011\fwidth}
  \begin{axis}[%
  legend columns=4,
    width=\fwidth,
    height=\fheight,
    area legend,
    scale only axis,
    xmin=0.25,
    xmax=11.75,
    xtick={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
    xticklabels={
      {$\begin{array}{c}
          10\\
          \phantom{...}
        \end{array}$
      },
      {$\begin{array}{c}
          20\\
          \text{proposed},\pi_{\text{Th}\phantom{...}}
        \end{array}$
      },
      {$\begin{array}{c}
          30\\
          \phantom{...}
        \end{array}$
      },
      {},
      {$\begin{array}{c}
          10\\
          \phantom{...}
        \end{array}$
      },
      {$\begin{array}{c}
          20\\
          \text{proposed},\kappa_{\text{Th}}
        \end{array}$
      },
      {$\begin{array}{c}
          30\\
          \phantom{...}
        \end{array}$
      },
      {},
      {$\begin{array}{c}10\\\phantom{...}\end{array}$},
      {$\begin{array}{c}20\\\text{DOA-based}\end{array}$},
      {$\begin{array}{c}30\\\phantom{...}\end{array}$}
    },
    ymin=0,
    ymax=100,
    ytick={0, 20, 40, 60, 80, 100},
    ylabel={$\text{Accuracy}$},
    y label style={at={(axis description cs:-0.08,.5)},rotate=0,anchor=south},
legend style={at={(0.5,-0.35)},anchor=north,draw=black,fill=white,legend cell align=left,
    /tikz/column 2/.style={column sep=5pt},
    /tikz/column 4/.style={column sep=5pt},
    /tikz/column 6/.style={column sep=5pt}
  }
    ]
    \addplot[
    ybar,
    bar width=\myBarWidth,
    bar shift=-3\myBarShift,
    draw=black,
    fill=mycolor1
    ]
    plot table[row sep=crcr] {%
      1  100\\  2  100\\  3  100\\  4  0\\
      5  100\\  6  100\\  7  100\\  8  0\\
      9  100\\ 10  100\\ 11  100\\
    };
\addlegendentry{$K = 0$};
    \addplot[
    ybar,
    bar width=\myBarWidth,
    bar shift=-2\myBarShift,
    draw=black,
    fill=mycolor2
    ]
    plot table[row sep=crcr] {%
      1 99.8\\  2  100\\  3  100\\  4  0\\
      5  100\\  6  100\\  7  100\\  8  0\\
      9 32.8\\ 10  100\\ 11  100\\
    };
\addlegendentry{$K = 1$};
    \addplot[
    ybar,
    bar width=\myBarWidth,
    bar shift=-1\myBarShift,
    draw=black,
    fill=mycolor3
    ]
    plot table[row sep=crcr] {%
      1  98.4\\  2  99.4\\  3  90.6\\  4  0\\
      5  98.2\\  6  97.4\\  7  90.4\\  8  0\\
      9  14.4\\ 10    79\\ 11  98.8\\
    };
\addlegendentry{$K = 2$};
    \addplot[
    ybar,
    bar width=\myBarWidth,
    bar shift=0\myBarShift,
    draw=black,
    fill=mycolor4
    ]
    plot table[row sep=crcr] {%
      1  87.4\\  2  99.4\\  3  95.8\\  4  0\\
      5  92.8\\  6  98.4\\  7  91.6\\  8  0\\
      9     1\\ 10  27.2\\ 11  79.6\\
    };
\addlegendentry{$K = 3$};
    \addplot[
    ybar,
    bar width=\myBarWidth,
    bar shift=1\myBarShift,
    draw=black,
    fill=mycolor5
    ]
    plot table[row sep=crcr] {%
      1  63.8\\  2  98.2\\  3  93.6\\  4  0\\
      5    80\\  6  94.4\\  7  85.4\\  8  0\\
      9     0\\ 10  34.4\\ 11  60.6\\
    };
\addlegendentry{$K = 4$};
    \addplot[
    ybar,
    bar width=\myBarWidth,
    bar shift=2\myBarShift,
    draw=black,
    fill=red!75!orange
    ]
    plot table[row sep=crcr] {%
      1  31.8\\  2    94\\  3    92\\  4  0\\
      5  56.6\\  6  81.8\\  7    83\\  8  0\\
      9   0.2\\ 10  40.6\\ 11  52.2\\
    };
\addlegendentry{$K = 5$};
    \addplot[
    ybar,
    bar width=\myBarWidth,
    bar shift=3\myBarShift,
    draw=black,
    fill=black!50!red
    ]
    plot table[row sep=crcr] {%
      1     7\\  2  57.2\\  3  56.6\\  4  0\\
      5  31.6\\  6    39\\  7  32.4\\  8  0\\
      9     0\\ 10     0\\ 11     0\\
    };
\addlegendentry{$K = 6$};
  \end{axis}
\end{tikzpicture}%

\end{document}

Pastebin

  • The clutter is due to the legend. Make it smaller and to the right and it would be OK. – percusse Sep 1 '14 at 19:34
  • That is indeed a good advice. How can I split up the xlabel such that I can add the labels on top of the figure? – Lukas Sep 1 '14 at 20:18
5

The modifications:

  1. Added font=\scriptsize in legend style.
  2. Moved legend to the top by at={(rel axis cs: 0.5,1.05)}
  3. Changed width to width=1.5\fwidth,
  4. Removed all \phantom{...}
  5. Added \\[-2.5ex] \underbrace{\hphantom{\text{roposed},\pi_{\text{Th}}}}\\[-0.5ex]

With these, we get

enter image description here

Code:

\documentclass{scrartcl}
\usepackage{pgfplots} % Import der Plots aus Matlab
%% \usepackage{tikz} % not needed pgfplots loads this too
\newlength{\fheight}
\newlength{\fwidth}
\pgfplotsset{compat=1.3}


\usepackage{amsmath,amsthm, amssymb, latexsym}

\begin{document}
\setlength\fheight{0.2\columnwidth}
\setlength\fwidth{0.42\columnwidth}

\definecolor{mycolor1}{rgb}{0.00000,0.00000,0.56250}%
\definecolor{mycolor2}{rgb}{0.00000,0.18750,1.00000}%
\definecolor{mycolor3}{rgb}{0.00000,0.87500,1.00000}%
\definecolor{mycolor4}{rgb}{0.56250,1.00000,0.43750}%
\definecolor{mycolor5}{rgb}{1.00000,0.81250,0.00000}%
%
\begin{tikzpicture}[baseline, trim axis left, trim axis right]
  \newlength{\myBarWidth}
  \setlength{\myBarWidth}{0.011\fwidth}
  \newlength{\myBarShift}
  \setlength{\myBarShift}{0.011\fwidth}
  \begin{axis}[%
  legend columns=4,
    width=1.5\fwidth,
    height=\fheight,
    area legend,
    scale only axis,
    xmin=0.25,
    xmax=11.75,
    xtick={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
    xticklabels={
      {$\begin{array}{c}
          10
        \end{array}$
      },
      {$\begin{array}{c}
          20\\[-2.5ex]
          \underbrace{\hphantom{\text{roposed},\pi_{\text{Th}}}}\\[-0.5ex]
          \text{proposed},\pi_{\text{Th}}
        \end{array}$
      },
      {$\begin{array}{c}
          30
        \end{array}$
      },
      {},
      {$\begin{array}{c}
          10
        \end{array}$
      },
      {$\begin{array}{c}
          20\\[-2.5ex]
          \underbrace{\hphantom{\text{roposed},\pi_{\text{Th}}}}\\[-0.5ex]
          \text{proposed},\kappa_{\text{Th}}
        \end{array}$
      },
      {$\begin{array}{c}
          30
        \end{array}$
      },
      {},
      {$\begin{array}{c}10\end{array}$},
      {$\begin{array}{c}20\\[-2.5ex]
          \underbrace{\hphantom{\text{roposed},\pi_{\text{Th}}}}\\[-0.5ex]\text{DOA-based}\end{array}$},
      {$\begin{array}{c}30\end{array}$}
    },
    ymin=0,
    ymax=100,
    ytick={0, 20, 40, 60, 80, 100},
    ylabel={$\text{Accuracy}$},
    y label style={at={(axis description cs:-0.08,.5)},rotate=0,anchor=south},
legend style={at={(rel axis cs: 0.5,1.05)},anchor=south,draw=black,font=\scriptsize,fill=white,legend cell align=left,
    /tikz/column 2/.style={column sep=5pt},
    /tikz/column 4/.style={column sep=5pt},
    /tikz/column 6/.style={column sep=5pt}
  }
    ]
    \addplot[
    ybar,
    bar width=\myBarWidth,
    bar shift=-3\myBarShift,
    draw=black,
    fill=mycolor1
    ]
    plot table[row sep=crcr] {%
      1  100\\  2  100\\  3  100\\  4  0\\
      5  100\\  6  100\\  7  100\\  8  0\\
      9  100\\ 10  100\\ 11  100\\
    };
\addlegendentry{$K = 0$};
    \addplot[
    ybar,
    bar width=\myBarWidth,
    bar shift=-2\myBarShift,
    draw=black,
    fill=mycolor2
    ]
    plot table[row sep=crcr] {%
      1 99.8\\  2  100\\  3  100\\  4  0\\
      5  100\\  6  100\\  7  100\\  8  0\\
      9 32.8\\ 10  100\\ 11  100\\
    };
\addlegendentry{$K = 1$};
    \addplot[
    ybar,
    bar width=\myBarWidth,
    bar shift=-1\myBarShift,
    draw=black,
    fill=mycolor3
    ]
    plot table[row sep=crcr] {%
      1  98.4\\  2  99.4\\  3  90.6\\  4  0\\
      5  98.2\\  6  97.4\\  7  90.4\\  8  0\\
      9  14.4\\ 10    79\\ 11  98.8\\
    };
\addlegendentry{$K = 2$};
    \addplot[
    ybar,
    bar width=\myBarWidth,
    bar shift=0\myBarShift,
    draw=black,
    fill=mycolor4
    ]
    plot table[row sep=crcr] {%
      1  87.4\\  2  99.4\\  3  95.8\\  4  0\\
      5  92.8\\  6  98.4\\  7  91.6\\  8  0\\
      9     1\\ 10  27.2\\ 11  79.6\\
    };
\addlegendentry{$K = 3$};
    \addplot[
    ybar,
    bar width=\myBarWidth,
    bar shift=1\myBarShift,
    draw=black,
    fill=mycolor5
    ]
    plot table[row sep=crcr] {%
      1  63.8\\  2  98.2\\  3  93.6\\  4  0\\
      5    80\\  6  94.4\\  7  85.4\\  8  0\\
      9     0\\ 10  34.4\\ 11  60.6\\
    };
\addlegendentry{$K = 4$};
    \addplot[
    ybar,
    bar width=\myBarWidth,
    bar shift=2\myBarShift,
    draw=black,
    fill=red!75!orange
    ]
    plot table[row sep=crcr] {%
      1  31.8\\  2    94\\  3    92\\  4  0\\
      5  56.6\\  6  81.8\\  7    83\\  8  0\\
      9   0.2\\ 10  40.6\\ 11  52.2\\
    };
\addlegendentry{$K = 5$};
    \addplot[
    ybar,
    bar width=\myBarWidth,
    bar shift=3\myBarShift,
    draw=black,
    fill=black!50!red
    ]
    plot table[row sep=crcr] {%
      1     7\\  2  57.2\\  3  56.6\\  4  0\\
      5  31.6\\  6    39\\  7  32.4\\  8  0\\
      9     0\\ 10     0\\ 11     0\\
    };
\addlegendentry{$K = 6$};
  \end{axis}
\end{tikzpicture}%

\end{document}

Here is another layout:

\documentclass{scrartcl}
\usepackage{pgfplots} % Import der Plots aus Matlab
%% \usepackage{tikz} % not needed pgfplots loads this too
\newlength{\fheight}
\newlength{\fwidth}
\pgfplotsset{compat=1.3}


\usepackage{amsmath,amsthm, amssymb, latexsym}

\begin{document}
\setlength\fheight{0.2\columnwidth}
\setlength\fwidth{0.42\columnwidth}

\definecolor{mycolor1}{rgb}{0.00000,0.00000,0.56250}%
\definecolor{mycolor2}{rgb}{0.00000,0.18750,1.00000}%
\definecolor{mycolor3}{rgb}{0.00000,0.87500,1.00000}%
\definecolor{mycolor4}{rgb}{0.56250,1.00000,0.43750}%
\definecolor{mycolor5}{rgb}{1.00000,0.81250,0.00000}%
%
\begin{tikzpicture}[baseline, trim axis left, trim axis right]
  \newlength{\myBarWidth}
  \setlength{\myBarWidth}{0.011\fwidth}
  \newlength{\myBarShift}
  \setlength{\myBarShift}{0.011\fwidth}
  \begin{axis}[%
  legend columns=4,
    width=1.5\fwidth,
    height=\fheight,
    area legend,
    scale only axis,
    clip=false,
    xmin=0.25,
    xmax=11.75,
    xtick={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},
    xticklabels={
      {$\begin{array}{c}
          10
        \end{array}$
      },
      {$\begin{array}{c}
          20
        \end{array}$
      },
      {$\begin{array}{c}
          30
        \end{array}$
      },
      {},
      {$\begin{array}{c}
          10
        \end{array}$
      },
      {$\begin{array}{c}
          20
        \end{array}$
      },
      {$\begin{array}{c}
          30
        \end{array}$
      },
      {},
      {$\begin{array}{c}10\end{array}$},
      {$\begin{array}{c}20\end{array}$},
      {$\begin{array}{c}30\end{array}$}
    },
    ymin=0,
    ymax=100,
    ytick={0, 20, 40, 60, 80, 100},
    ylabel={$\text{Accuracy}$},
    y label style={at={(axis description cs:-0.08,.5)},rotate=0,anchor=south},
legend style={at={(rel axis cs: 0.5,-0.3)},anchor=north,draw=black,font=\scriptsize,fill=white,legend cell align=left,
    /tikz/column 2/.style={column sep=5pt},
    /tikz/column 4/.style={column sep=5pt},
    /tikz/column 6/.style={column sep=5pt}
  }
    ]
    \addplot[
    ybar,
    bar width=\myBarWidth,
    bar shift=-3\myBarShift,
    draw=black,
    fill=mycolor1
    ]
    plot table[row sep=crcr] {%
      1  100\\  2  100\\  3  100\\  4  0\\
      5  100\\  6  100\\  7  100\\  8  0\\
      9  100\\ 10  100\\ 11  100\\
    };
\addlegendentry{$K = 0$};
    \addplot[
    ybar,
    bar width=\myBarWidth,
    bar shift=-2\myBarShift,
    draw=black,
    fill=mycolor2
    ]
    plot table[row sep=crcr] {%
      1 99.8\\  2  100\\  3  100\\  4  0\\
      5  100\\  6  100\\  7  100\\  8  0\\
      9 32.8\\ 10  100\\ 11  100\\
    };
\addlegendentry{$K = 1$};
    \addplot[
    ybar,
    bar width=\myBarWidth,
    bar shift=-1\myBarShift,
    draw=black,
    fill=mycolor3
    ]
    plot table[row sep=crcr] {%
      1  98.4\\  2  99.4\\  3  90.6\\  4  0\\
      5  98.2\\  6  97.4\\  7  90.4\\  8  0\\
      9  14.4\\ 10    79\\ 11  98.8\\
    };
\addlegendentry{$K = 2$};
    \addplot[
    ybar,
    bar width=\myBarWidth,
    bar shift=0\myBarShift,
    draw=black,
    fill=mycolor4
    ]
    plot table[row sep=crcr] {%
      1  87.4\\  2  99.4\\  3  95.8\\  4  0\\
      5  92.8\\  6  98.4\\  7  91.6\\  8  0\\
      9     1\\ 10  27.2\\ 11  79.6\\
    };
\addlegendentry{$K = 3$};
    \addplot[
    ybar,
    bar width=\myBarWidth,
    bar shift=1\myBarShift,
    draw=black,
    fill=mycolor5
    ]
    plot table[row sep=crcr] {%
      1  63.8\\  2  98.2\\  3  93.6\\  4  0\\
      5    80\\  6  94.4\\  7  85.4\\  8  0\\
      9     0\\ 10  34.4\\ 11  60.6\\
    };
\addlegendentry{$K = 4$};
    \addplot[
    ybar,
    bar width=\myBarWidth,
    bar shift=2\myBarShift,
    draw=black,
    fill=red!75!orange
    ]
    plot table[row sep=crcr] {%
      1  31.8\\  2    94\\  3    92\\  4  0\\
      5  56.6\\  6  81.8\\  7    83\\  8  0\\
      9   0.2\\ 10  40.6\\ 11  52.2\\
    };
\addlegendentry{$K = 5$};
    \addplot[
    ybar,
    bar width=\myBarWidth,
    bar shift=3\myBarShift,
    draw=black,
    fill=black!50!red
    ]
    plot table[row sep=crcr] {%
      1     7\\  2  57.2\\  3  56.6\\  4  0\\
      5  31.6\\  6    39\\  7  32.4\\  8  0\\
      9     0\\ 10     0\\ 11     0\\
    };
\addlegendentry{$K = 6$};
  \node[anchor=south] at (axis cs: 2,105) {$\begin{array}{c}
          \text{proposed},\pi_{\text{Th}}\\[-0.7ex]
          \overbrace{\hphantom{\text{roposed},\pi_{\text{Th}}}}\\[-2.25ex]
        \end{array}$};
  \node[anchor=south] at (axis cs: 6,105) {
          $\begin{array}{c}
          \text{proposed},\kappa_{\text{Th}}\\[-0.7ex]
          \overbrace{\hphantom{\text{roposed},\kappa_{\text{Th}}}}\\[-2.25ex]
        \end{array}$};
  \node[anchor=south] at (axis cs: 10,105) {
          $\begin{array}{c}
          \text{\text{DOA-based}}\\[-0.7ex]
          \overbrace{\hphantom{\text{roposed},\pi_{\text{Th}}}}\\[-2.25ex]
        \end{array}$};
  \end{axis}
\end{tikzpicture}%

\end{document}

enter image description here

| improve this answer | |
  • This is a great answer. I appreciate two varying answers. – Lukas Sep 2 '14 at 0:24

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.