0

I am trying to follow this example](https://tex.stackexchange.com/a/157028/122628) to draw a basic bar chart but the lines are getting mixed up. I think it's because major differences between the two columns.

enter image description here

\documentclass[border=0.2cm]{standalone}

\usepackage{pgfplots} \usetikzlibrary{patterns}

\begin{document}

\pgfplotstableread[row sep=\,col sep=&]{ interval & dynamic & static \ 0 & 0 & 0 \ 1 & 0 & 0 \ 2 & 0 & 0 \ 3 & 0 & 0 \ 4 & 0 & 0 \ 5 & 0 & 0 \ 6 & 0 & 0 \ 7 & 0 & 0 \ 8 & 0 & 0 \ 9 & 0 & 0 \ 10 & 0 & 0 \ 11 & 0 & 0 \ 12 & 0 & 0 \ 13 & 1 & 0 \ 14 & 46 & 6 \ 15 & 66 & 9 \ 16 & 157 & 18 \ 17 & 649 & 79 \ }\mydata

\begin{tikzpicture} \begin{axis}[ ybar, legend style={at={(0.5,1)}, anchor=north,legend columns=-1}, symbolic x coords={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17} xtick=data, nodes near coords, nodes near coords align={vertical}, ylabel={%}, ] \addplot table[x=interval,y=dynamic]{\mydata}; \addplot table[x=interval,y=static]{\mydata}; \legend{Dynamic,Static} \end{axis} \end{tikzpicture}

\end{document}

Stefan Pinnow
  • 29,535
Node.JS
  • 685

1 Answers1

1

With only minimal changes to the code (see corresponding comments in the code)

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
        \pgfplotstableread[row sep=\\,col sep=&]{
            interval & dynamic & static \\
            0  & 0  & 0  \\
            1  & 0  & 0  \\
            2  & 0  & 0  \\
            3  & 0  & 0  \\
            4  & 0  & 0  \\
            5  & 0  & 0  \\
            6  & 0  & 0  \\
            7  & 0  & 0  \\
            8  & 0  & 0  \\
            9  & 0  & 0  \\
            10  & 0  & 0  \\
            11  & 0  & 0  \\
            12  & 0  & 0  \\
            13  & 1  & 0  \\
            14  & 46  & 6  \\
            15  & 66  & 9  \\
            16  & 157  & 18  \\
            17  & 649  & 79  \\
        }\mydata
    \begin{axis}[
        width=10cm,
        height=7cm,
        ybar,
        % to make the individual bars independent of the `width' of the
        % surrounding axis give a `bar width' in axis units
        /pgf/bar width=1,
        legend style={at={(0.5,0.98)},
            anchor=north,legend columns=-1},
%        symbolic x coords={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17},   % <-- the trailing comma was missing
        xtick=data,
        nodes near coords,
%        nodes near coords align={vertical},    % not needed
        nodes near coords style={
        ylabel={\%},
    ]
        \addplot table[x=interval,y=dynamic]{\mydata};
        \addplot table[x=interval,y=static]{\mydata};
        \legend{Dynamic,Static}
    \end{axis}
\end{tikzpicture}
\end{document}

I get

image showing the result of above code

Stefan Pinnow
  • 29,535