我尝试将显示在条形图旁边的纯值更改为百分比,但没有效果:
% change to percentage
\pgfplotsset{
percentage plot/.style={
nodes near coords align=horizontal,
xticklabel=\pgfmathprintnumber{\tick}\,$\%$,
xmin=0, xmax=100,
visualization depends on={x \as \originalvalue}
}
}
主要文件如下:
\begin{tikzpicture}
\begin{axis}[
xbar,
axis x line = bottom,
axis y line = left,
ytick=\empty,
y=0.5cm, enlarge y limits={true, abs value=0.75},
enlarge x limits={upper, value=0.15},
xlabel=,
ylabel=,
xmajorgrids=true,
xtick style={draw=none},
ytick style={draw=none},
yticklabels={,},
nodes near coords, nodes near coords align=horizontal,
percentage plot
]
\addplot [draw opacity=0, fill=verylightgrey, discard if={num}{1}] table [x=value, y=num] {risk.dat};
\addplot [draw opacity=0, fill=lightred, discard if not={num}{1}] table [x=value, y=num, y expr=\coordindex] {risk.dat};
\end{axis}
\end{tikzpicture}
结果是(红色的是我想要的):
答案1
您可以使用自定义代码修改pgfplots
通过键写入的内容nodes near coords*
。对于您的情况,可以通过以下方式添加百分号
nodes near coords*={\pgfmathprintnumber\pgfplotspointmeta \%}
请参阅手册以了解更多详细信息。