我创建了一个带有对数 x 轴的条形图。问题是:条形的标签也是对数的,例如1.3代替20。
我怎样才能获得真实的数字作为标签?
提前致谢。
梅威瑟:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
xbar,
xbar=0pt,
enlargelimits=0.15,
width=.9\textwidth,
label style={font=\footnotesize},
ytick={0,...,9},
yticklabels = {val1, val2, val3, val4, val5, val6, val7, val8, val9, val10},
ytick=data,
enlarge y limits={abs=1.125},
nodes near coords,
every axis plot/.append style={fill},
y = 1.2cm,
xmode=log,log basis x=10
]
\addplot coordinates {(168000, 0) (832, 1) (2696, 2) (131162, 3) (31492, 4) (6, 5) (2858, 6) (152196, 7) (698264, 8) (1100, 9)};
\addplot coordinates {(2487066, 0) (34174, 1) (44184, 2) (409040, 3) (68204, 4) (35200, 5) (35528, 6) (656328, 7) (702332, 8) (38348, 9)};
\addplot coordinates {(188540, 0) (1268, 1) (1848, 2) (159124, 3) (32788, 4) (836, 5) (2888, 6) (146236, 7) (499024, 8) (2696, 9)};
\end{axis}
\end{tikzpicture}
\end{document}
结果:
答案1
point meta=rawx
这可以通过添加选项来实现axis
。
因为这似乎“混淆”了默认值,所以您也nodes near coords align=auto
需要设置该值。horizontal
% used PGFPlots v1.17
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xbar=0pt,
enlargelimits=0.15,
width=.9\textwidth,
label style={font=\footnotesize},
ytick={0,...,9},
yticklabels = {val1, val2, val3, val4, val5, val6, val7, val8, val9, val10},
ytick=data,
enlarge y limits={abs=1.125},
nodes near coords,
nodes near coords align=horizontal, % <-- added
point meta=rawx, % <-- added
every axis plot/.append style={fill},
y = 1.2cm,
xmode=log,log basis x=10
]
\addplot coordinates {(168000, 0) (832, 1) (2696, 2) (131162, 3) (31492, 4) (6, 5) (2858, 6) (152196, 7) (698264, 8) (1100, 9)};
\addplot coordinates {(2487066, 0) (34174, 1) (44184, 2) (409040, 3) (68204, 4) (35200, 5) (35528, 6) (656328, 7) (702332, 8) (38348, 9)};
\addplot coordinates {(188540, 0) (1268, 1) (1848, 2) (159124, 3) (32788, 4) (836, 5) (2888, 6) (146236, 7) (499024, 8) (2696, 9)};
\end{axis}
\end{tikzpicture}
\end{document}