这是我第一次使用 pgfplots,并尝试为论文生成条形图。这是我拥有的源代码,但我想将两组条形图置于图表中间。有什么想法可以做到这一点吗?
\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}
答案1
欢迎光临!类似这样的事吗?
\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}