4

I am trying to create a grouped bar chart with pgfplots from a file that contains a data table. However in the resulting picture the bars are not grouped but on top of each other.

Every working example of grouped bar charts with pgfplots I found in the documentation, at stackoverflow or with google includes the coordinates in the tex file itself (those example work for me too).

The bars should be in pairs with one pair for each value of rounds. The first bar of each pair should be the corresponding value of RRS. The second bar of each pair should be the corresponding value of QRC.

My tex file

\documentclass[a4paper,10pt]{article}

\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}

\pgfplotsset{compat=1.8}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[ybar]
    \pgfplotstableread{frequency_comparison_23.dat}\loadedtable;

    \addplot table[x=rounds, y=RRS] {\loadedtable};
    \addplot table[x=rounds, y=QRC] {\loadedtable};    
  \end{axis}
\end{tikzpicture}
\end{document}

And the table "frequency_comparison_23.dat"

vertices rounds RRS QRC
8388608 37 47 727
8388608 38 5731 15709
8388608 39 29072 35103
8388608 40 33027 26904
8388608 41 18914 13062
8388608 42 8141 5291
8388608 43 3177 1999
8388608 44 1179 766
8388608 45 435 273
8388608 46 175 104
8388608 47 59 43
8388608 48 26 11
8388608 49 9 5
8388608 50 6 3
8388608 51 1 0
8388608 52 1 0

migrated from stackoverflow.com May 8 '13 at 15:53

This question came from our site for professional and enthusiast programmers.

  • Welcome to TeX.sx! Your post was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other (by using the same OpenID), otherwise you won't be able to comment on or accept answers or edit your question. – Werner May 9 '13 at 1:20
3

You are using the default bar width option and they tend to overlap. If you adjust the bar width or the width of the plot it works.

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}

\pgfplotsset{compat=1.8}

    \pgfplotstableread{
vertices rounds RRS QRC
8388608 37 47 727
8388608 38 5731 15709
8388608 39 29072 35103
8388608 40 33027 26904
8388608 41 18914 13062
8388608 42 8141 5291
8388608 43 3177 1999
8388608 44 1179 766
8388608 45 435 273
8388608 46 175 104
8388608 47 59 43
8388608 48 26 11
8388608 49 9 5
8388608 50 6 3
8388608 51 1 0
8388608 52 1 0
}\loadedtable;


\begin{document}
\begin{tikzpicture}
  \begin{axis}[ybar,bar width=2pt]
    \addplot table[x=rounds, y=RRS] {\loadedtable};
    \addplot table[x=rounds, y=QRC] {\loadedtable};    
  \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

  • @svenhuebner My pleasure. – percusse May 9 '13 at 7: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.