2

I am using pgfplots for the first time and trying to generate bar charts for a paper. This is the source code that I have, but I want to center the two sets of the bars in the middle of the chart. Any ideas how this can be done?

\begin{tikzpicture}[trim axis left, trim axis right]
\begin{axis}[
    ybar,
    enlargelimits=0.15,
    legend style={at={(0.5,-0.15)},
      anchor=north,legend columns=-1,},
    ylabel={Negative Log Likelihood},
    symbolic x coords={Dataset 1,Dataset 2},
    xtick=data,
    x tick label style={ align=center},
    ]
\addplot coordinates {(Dataset 1,400) (Dataset 2,751)};
\addplot coordinates {(Dataset 1,391) (Dataset 2,751)};
\addplot coordinates {(Dataset 1,270) (Dataset 2,720)};
\legend{Algo 1,Algo 2,Algo 3}
\end{axis}
\end{tikzpicture}

enter image description here

1

Welcome! Something like this?

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ybar,
    enlarge x limits=1,
    legend style={at={(0.5,-0.15)},
      anchor=north,legend columns=-1,},
    ylabel={Negative Log Likelihood},
    symbolic x coords={Dataset 1,Dataset 2},
    xtick=data,
    x tick label style={ align=center},
    ]
\addplot coordinates {(Dataset 1,400) (Dataset 2,751)};
\addplot coordinates {(Dataset 1,391) (Dataset 2,751)};
\addplot coordinates {(Dataset 1,270) (Dataset 2,720)};
\legend{Algo 1,Algo 2,Algo 3}
\end{axis}
\end{tikzpicture}
\end{document}

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.