在長條圖中移動條形

在長條圖中移動條形

如何讓右側的條形出現在左側的條狀旁邊,這樣看起來就沒那麼愚蠢了?

在此輸入影像描述

圖的 LateX 程式碼:

\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}

答案1

您可以使用 鍵將 x 軸的限制放大一個因子enlarge x limits長條圖

\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}

相關內容