1

How do you make the bars on the right appear next to the bars on the left, so it doesn't look so silly?

enter image description here

LateX code for figure:

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}
    % Data
    %----------------------------------------
    \pgfplotstableread[row sep=\\,col sep=&]{
        descr & DCPT & RPT            \\
        Description1     & 0.664  & 0.583 \\
        Description2     & 0.471  & 0.10  \\
        }\mydata

    % Plot
    %----------------------------------------
    \begin{figure}[!htb]
    \centering
    \begin{tikzpicture}
        \begin{axis}[
                ybar = 7pt,
                symbolic x coords={Description1, Description2},
                xticklabel style={rotate=45},
                xtick=data,
                nodes near coords,
                nodes near coords align={vertical},
                ymin=0, ymax=0.8,
            ]
            \addplot table[x=descr,y=DCPT]{\mydata};
            \addplot table[x=descr,y=RPT]{\mydata};
            \legend{Data1, Data2}
        \end{axis}
        \end{tikzpicture}
        \caption{Caption.}
        \label{fig:statistics}
    \end{figure}
\end{document}
2
  • Could you please make your code compilable? Please also clarify: Where should the legend be placed?
    – leandriis
    Mar 26, 2020 at 19:12
  • My appologies, the code is now compilable. The legend is not really important as long as it's visible. I just want the bars to be next to each other.
    – C. K.
    Mar 26, 2020 at 19:18

1 Answer 1

2

You can enlarge the limits of the x axis by a factor with the enlarge x limits key. bar-plot

\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}
    % Data
    %----------------------------------------
    \pgfplotstableread[row sep=\\,col sep=&]{
        descr & DCPT & RPT            \\
        Description1     & 0.664  & 0.583 \\
        Description2     & 0.471  & 0.10  \\
        }\mydata

    % Plot
    %----------------------------------------
    \begin{figure}[!htb]
    \centering
    \begin{tikzpicture}
        \begin{axis}[
                ybar = 7pt,
                symbolic x coords={Description1, Description2},
                xticklabel style={rotate=45},
                xtick=data,
                enlarge x limits = 0.5,
                nodes near coords,
                nodes near coords align={vertical},
                ymin=0, ymax=0.8,
            ]
            \addplot table[x=descr,y=DCPT]{\mydata};
            \addplot table[x=descr,y=RPT]{\mydata};
            \legend{Data1, Data2}
        \end{axis}
        \end{tikzpicture}
        \caption{Caption.}
        \label{fig:statistics}
    \end{figure}
\end{document}

You must log in to answer this question.

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