我在使用以下代码生成图表时遇到了问题。我不知道为什么第一组 (Yago) 不包括第一个条目(Sys1 的蓝色条目),而第二组不包括最后一个条目(Sys6 的绿色条目)。如有任何建议,我们将不胜感激。
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
major x tick style = transparent,
xtick=data,
ybar,
ymin = 0,
ymax = 100,
ymajorgrids = true,
ylabel = {Offline Time (in min.)},
xlabel = {Data Set},
symbolic x coords = {Yago,DBLP},
ytick = {0,20,40,60,80,100},
scaled y ticks = false,
bar width=10pt,
]
\addplot coordinates {(Yago,20) (DBLP,12)};
\addplot coordinates {(Yago,45) (DBLP,30)};
\addplot coordinates {(Yago,30) (DBLP,15)};
\addplot coordinates {(Yago,65) (DBLP,45)};
\addplot coordinates {(Yago,25) (DBLP,14)};
\addplot coordinates {(Yago,35) (DBLP,25)};
\legend{Sys1,Sys2,Sys3,Sys4,Sys5,Sys6}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
条形图在那里,但是没有足够的空间让它们出现:您可以使用enlarge x limits
和/或减少bar width
:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
major x tick style = transparent,
xtick=data,
ybar,
ymin = 0,
ymax = 100,
ymajorgrids = true,
ylabel = {Offline Time (in min.)},
xlabel = {Data Set},
symbolic x coords = {Yago,DBLP},
ytick = {0,20,40,60,80,100},
scaled y ticks = false,
bar width=6pt,
enlarge x limits=0.25,
]
\addplot coordinates {(Yago,20) (DBLP,12)};
\addplot coordinates {(Yago,45) (DBLP,30)};
\addplot coordinates {(Yago,30) (DBLP,15)};
\addplot coordinates {(Yago,65) (DBLP,45)};
\addplot coordinates {(Yago,25) (DBLP,14)};
\addplot coordinates {(Yago,35) (DBLP,25)};
\legend{Sys1,Sys2,Sys3,Sys4,Sys5,Sys6}
\end{axis}
\end{tikzpicture}
\end{document}