e
无论d
前一个数据点是否存在,数据点都会被忽略。我希望、、和出现在a
将条形图按两个分组的条形图中(因此请随意尝试)。b
c
d
e
最小示例:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title=ML Model Training,
ylabel=Elapsed Time (seconds),
xlabel=ML Model,
ybar interval=0.7,
symbolic x coords={a, b, c, d, e},
xtick=data,
]
\addplot coordinates {
(a,157.9)
(b, 2.99)
(c, 11.71)
(d, 91.5)
(e, 406.3)
};
\addplot coordinates {
(a,57.9)
(b, 12.99)
(c, 21.71)
(d, 21.5)
(e, 106.3)
};
\end{axis}
\end{tikzpicture}
\end{document}
这使:
d
现在即便我从符号坐标和坐标列表中注释掉,e
仍然不会显示:
请问我遗漏了什么?
答案1
你不应该使用ybar interval
但是ybar
(见这个答案):
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title=ML Model Training,
ylabel=Elapsed Time (seconds),
xlabel=ML Model,
ybar=0.7,
symbolic x coords={a, b, c, d, e},
xtick=data,
]
\addplot coordinates {
(a, 157.9)
(b, 2.99)
(c, 11.71)
(d, 91.5)
(e, 406.3)
};
\addplot coordinates {
(a, 57.9)
(b, 12.99)
(c, 21.71)
(d, 21.5)
(e, 106.3)
};
\end{axis}
\end{tikzpicture}
\end{document}
为了获得与原始图类似的外观,您可以xminorgrids=true, minor tick num=1
再次使用添加垂直线,用删除主要刻度,major tick style={draw=none}
最后用调整间距enlarge x limits=0.125
。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title=ML Model Training,
ylabel=Elapsed Time (seconds),
xlabel=ML Model,
ybar=0.7,
xminorgrids=true,
minor tick num=1,
symbolic x coords={a, b, c, d, e},
xtick=data,
typeset ticklabels with strut, % align tick labels vertically
major tick style={draw=none},
enlarge x limits=0.125
]
\addplot coordinates {
(a, 157.9)
(b, 2.99)
(c, 11.71)
(d, 91.5)
(e, 406.3)
};
\addplot coordinates {
(a, 57.9)
(b, 12.99)
(c, 21.71)
(d, 21.5)
(e, 106.3)
};
\end{axis}
\end{tikzpicture}
\end{document}