0

I am sure this is quite a trivial problem, but I cannot seem to figure it out. I have a bar-chart with preferably three groups of four bars. The thing is, using the MWE below, the four bars per group are all stacked together instead of nicely next to each other. I cannot find any significant changes from MWE's from similar questions which do seem to have what I want (i.e. Grouped bar charts).

MWE here:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\begin{document}

\begin{figure}[h]
    \centering
    \begin{tikzpicture}
        \begin{axis}[
            symbolic x coords={tree,indentation,parentheses},
            ytick = {0,5000,10000,15000,20000,25000,30000,35000},
            ymin = 0,
            ymajorgrids = true,
            ymax=35000,
            scaled ticks= false,
            ylabel = {Average response time(ms)},
            xtick=data]
            %Average
            \addplot[ybar,fill=gray, mark=none] coordinates {
                (tree,20962)
                (indentation,24509)
                (parentheses,33054)
            };
            %Organizational
            \addplot[ybar,fill=blue] coordinates {
                (tree,22060)
                (indentation,21255)
                (parentheses,34917)
            };
            %Folder
            \addplot[ybar,fill=black] coordinates {
                (tree,17776)
                (indentation,15050)
                (parentheses,27904)
            };
            %Arithmetics
            \addplot[ybar,fill=green] coordinates {
                (tree,23599)
                (indentation,22923)
                (parentheses,17693)
            };
        \end{axis}

    \end{tikzpicture}
    \caption{Average response time for each representation type}
    \label{fig:avg_reptime}
\end{figure}

\end{document}

Perhaps it is worth noting I'm working in compatibility version 1.13 (hence the \pgfplotsset{compat=1.13}.

Thanks in advance.

1

In your case you need ybar as option in axis instead of \addplot.

Also you will need enlarge x limits to enlarge x axis.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\begin{document}

\begin{figure}[h]
    \centering
    \begin{tikzpicture}
        \begin{axis}[
            symbolic x coords={tree,indentation,parentheses},
            ytick = {0,5000,10000,15000,20000,25000,30000,35000},
            ymin = 0,
            ymajorgrids = true,
            ymax=35000,
            ybar,
            scaled ticks= false,
            ylabel = {Average response time(ms)},
            xtick=data,
            enlarge x limits=0.2]
            %Average
            \addplot[fill=gray, mark=none] coordinates {
                (tree,20962)
                (indentation,24509)
                (parentheses,33054)
            };
            %Organizational
            \addplot[fill=blue] coordinates {
                (tree,22060)
                (indentation,21255)
                (parentheses,34917)
            };
            %Folder
            \addplot[fill=black] coordinates {
                (tree,17776)
                (indentation,15050)
                (parentheses,27904)
            };
            %Arithmetics
            \addplot[fill=green] coordinates {
                (tree,23599)
                (indentation,22923)
                (parentheses,17693)
            };
        \end{axis}

    \end{tikzpicture}
    \caption{Average response time for each representation type}
    \label{fig:avg_reptime}
\end{figure}

\end{document}

Output

enter image description here

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.