1

I am trying to draw a group tikz barchart (2 groups, 4 bars each) in Latex. I looked at all the questions and answers here but couldn't find a similar problem. My problem is that the graph output has 6 groups instead of 2. The graph should have 2 groups D1 and D2 and 4 bars in each group 1K, 1M, 10M and 100M

enter image description here

Here is my code:

\begin{figure}
\begin{tikzpicture}
\begin{axis}[
    x tick label style={
        /pgf/number format/1000 sep=},
    ylabel=Time in Milliseconds,
    symbolic x coords={D1,D2},
    enlargelimits=0.15,
    legend style={at={(0.5,-0.15)},
        anchor=north,legend columns=-1,draw=none},
    ybar,
    bar width=7pt,
]

\addplot[fill=blue!70!gray,draw=none] coordinates {(D1,0.589) (D2,8.4)};
\addplot[fill=gray!80!white,draw=none] coordinates {(D1,0.584) (D2,8.229)};
\addplot[fill=green!30!gray,draw=none] coordinates {(D1,0.599) (D2,8.109)};
\addplot[fill=blue!30!gray,draw=none] coordinates {(D1,0.615) (D2,9.13)};

\legend{1K,1M,10M,100M}
\end{axis}
\end{tikzpicture}
\caption{Time comparison}
\label{fig:readdsplot}
\end{figure}

Thanks in advance.

0

1 Answer 1

1

The usual format for questions is to provide a complete document that starts with \documentclass and ends with \end{document}, and can be compiled. Only then others can easily try things out. As for your question, you need to add xtick=data to avoid the unnecessary ticks.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}

\begin{figure}
\begin{tikzpicture}
\begin{axis}[
    x tick label style={
        /pgf/number format/1000 sep=},
    ylabel=Time in Milliseconds,
    symbolic x coords={D1,D2},xtick=data,
    enlargelimits=0.15,
    legend style={at={(0.5,-0.15)},
        anchor=north,legend columns=-1,draw=none},
    ybar,
    bar width=7pt,
]
\addplot[fill=blue!70!gray,draw=none] coordinates {(D1,0.589) (D2,8.4)};
\addplot[fill=gray!80!white,draw=none] coordinates {(D1,0.584) (D2,8.229)};
\addplot[fill=green!30!gray,draw=none] coordinates {(D1,0.599) (D2,8.109)};
\addplot[fill=blue!30!gray,draw=none] coordinates {(D1,0.615) (D2,9.13)};
\legend{1K,1M,10M,100M}
\end{axis}
\end{tikzpicture}
\caption{Time comparison}
\label{fig:readdsplot}
\end{figure}
\end{document}

enter image description here

1
  • That worked. Thank you.
    – MoeS
    Sep 13, 2019 at 17:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .