我想省略前导零(即小数点前),以避免数字重叠。它也能满足 APA 样式,因为值始终在 [0-1] 范围内。这就是我现在所拥有的:
使用以下乳胶代码:
\begin{tikzpicture}
\begin{axis}[
width = 1.1*\columnwidth,
height = 8cm,
ybar=0pt,
enlarge x limits=0.25,
major x tick style = transparent,
bar width=12pt,
symbolic x coords={Recall, Precision, F$_1$},
xtick = data, ymin=0, ymax=0.1,
scaled y ticks = false,
yticklabel style={/pgf/number format/fixed},
nodes near coords,
every node near coord/.append style = {
anchor=south,
/pgf/number format/.cd,
fixed,
precision=2,
}
]
\addplot[style={fill=bblue}]
coordinates {(Recall,.057) (Precision,.007) (F$_1$,.014)};
\addplot[style={fill=rred}]
coordinates {(Recall,.057) (Precision,.005) (F$_1$,.009)};
\addplot[style={fill=ggreen}]
coordinates {(Recall,.091) (Precision,.008) (F$_1$,.015)};
\addplot[style={fill=ppurple}]
coordinates {(Recall,0) (Precision,0) (F$_1$,0)};
\addplot[style={fill=yyellow}]
coordinates {(Recall,.023) (Precision,.004) (F$_1$,.007)};
\end{axis}
\end{tikzpicture}
在https://tex.stackexchange.com/a/102154@Jake 在文本中的任何位置打印数字时提供了解决此问题的解决方案,但是当我在 tikzpicture 的设置中尝试这些解决方案时,出现了一些错误。
我尝试将该skip 0.
设置添加到轴选项中,但没有成功。如果有人知道如何添加此设置,我将不胜感激!
答案1
我不确定为什么skip 0.
对你不起作用。我使用了以下代码,输出看起来像预期的那样:
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width = 1.1*\columnwidth,
height = 8cm,
ybar=0pt,
enlarge x limits=0.25,
major x tick style = transparent,
bar width=12pt,
symbolic x coords={Recall, Precision, F$_1$},
xtick = data, ymin=0, ymax=0.1,
scaled y ticks = false,
yticklabel style={/pgf/number format/fixed,/pgf/number format/fixed zerofill,/pgf/number format/precision=2},
nodes near coords,
every node near coord/.append style = {
anchor=south,
font=\footnotesize,
/pgf/number format/.cd,
/pgf/number format/fixed,
/pgf/number format/fixed zerofill,
/pgf/number format/precision=2,
skip 0.
}
]
\addplot[style={fill=blue}] coordinates {(Recall,.057) (Precision,.007) (F$_1$,.014)};
\addplot[style={fill=red}] coordinates {(Recall,.057) (Precision,.005) (F$_1$,.009)};
\addplot[style={fill=green}] coordinates {(Recall,.091) (Precision,.008) (F$_1$,.015)};
\addplot[style={fill=purple}] coordinates {(Recall,.00) (Precision,0) (F$_1$,0)};
\addplot[style={fill=yellow}] coordinates {(Recall,.023) (Precision,.004) (F$_1$,.007)};
\end{axis}
\end{tikzpicture}
\end{document}
看起来像这样:
我擅自将您的ytick
标签改得更统一,并将字体大小nodes near coords
改得适合您的栏目顶部。
注意:如果您希望将0
值显示为0
而不是 ,.00
则删除该行/pgf/number format/fixed zerofill,
。