pgfplots:具有不同条形数的中心条形图

pgfplots:具有不同条形数的中心条形图

pgfplots我尝试使用以下 LaTeX 代码创建条形图

\begin{figure}[H]
    \begin{minipage}{0.5\textwidth}
        \resizebox{\textwidth}{!}{%
        \begin{tikzpicture}[baseline]
            \begin{axis}[
            ybar,
            bar width=0.1cm,
            width= 7.4cm,
            xtick=data,
            symbolic x coords = {Base, Random, Unequal, Imbalanced}
            ]

            \addplot coordinates {(Base, 0.758) (Random, 0.733) (Unequal, 0.758) (Imbalanced, 0.819)};
            \addplot coordinates {(Random, 0.749) (Unequal, 0.72) (Imbalanced, 0.712)};
            \addplot coordinates {(Random, 0.729) (Unequal, 0.751) (Imbalanced, 0.587)};
            \addplot coordinates {(Random, 0.743) (Unequal, 0.749) (Imbalanced, 0.759)};
            \addplot coordinates {(Random, 0.762) (Unequal, 0.779) (Imbalanced, 0.773)};

            \end{axis}
        \end{tikzpicture}
        }
        \caption{Cachexia Dataset F1-Scores}\label{fig1}
    \end{minipage}%
    \begin{minipage}{0.5[![enter image description here][1]][1]\textwidth}
        \resizebox{\textwidth}{!}{%
        \begin{tikzpicture}[baseline]
            \begin{axis}[
            ybar,
            bar width=0.1cm,
            width=7.4cm,
            xtick=data,
            symbolic x coords = {Base, Random, Unequal, Imbalanced}
            ]

            \addplot coordinates {(Base, 0.715) (Random, 0.652) (Unequal, 0.69) (Imbalanced, 0.651)};
            \addplot coordinates {(Random, 0.631) (Unequal, 0.604) (Imbalanced, 0.64)};
            \addplot coordinates {(Random, 0.649) (Unequal, 0.61) (Imbalanced, 0.623)};
            \addplot coordinates {(Random, 0.693) (Unequal, 0.687) (Imbalanced, 0.681)};
            \addplot coordinates {(Random, 0.734) (Unequal, 0.729) (Imbalanced, 0.722)};

            \end{axis}
        \end{tikzpicture}
        }
        \caption{Cachexia Dataset AUC-ROC}\label{fig2}
    \end{minipage}%
\end{figure}

我能够制作以下图表

在此处输入图片描述

我想将最左边的栏置于中央,我应该如何修改我的代码来实现这一点?

谢谢!

答案1

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
bar width=0.1cm,
xtick=data,
symbolic x coords={Base, Random, Unequal, Imbalanced}
]
\addplot+[bar shift=0cm, forget plot] coordinates {(Base, 0.758)};
\addplot coordinates {(Random, 0.733) (Unequal, 0.758) (Imbalanced, 0.819)};
\addplot coordinates {(Random, 0.749) (Unequal, 0.72) (Imbalanced, 0.712)};
\addplot coordinates {(Random, 0.729) (Unequal, 0.751) (Imbalanced, 0.587)};
\addplot coordinates {(Random, 0.743) (Unequal, 0.749) (Imbalanced, 0.759)};
\addplot coordinates {(Random, 0.762) (Unequal, 0.779) (Imbalanced, 0.773)};
\end{axis}
\end{tikzpicture}
\end{document}

条状图

相关内容