对数条形图

对数条形图

我目前正在尝试创建一个图表,y 轴上有对数刻度。这基本上可行,只是值是nodes near coords错误的。没有ymode=log它,例如 20551 显示为标签。有ymode=log它显示 9.93。是否有可能获得线性模式的行为?(因此它再次显示 20551 而不是 9.93)

是否可以使图例自动居中?

\begin{tikzpicture}
\begin{axis}[
    width=0.8\textwidth,
    ybar,
    enlargelimits=0.15,
    ylabel={\#Pathes},
    ymode=log,
    log ticks with fixed point,
    xlabel={Test},
    symbolic x coords={1 - 10, 11 - 100, 101 - 1000, 1001 - 10000, >10000},
    xtick=data,
    nodes near coords={\pgfmathprintnumber{\pgfplotspointmeta}},
    nodes near coords align={vertical},
    legend style={at={(0,-2.5em)}, draw=none, anchor=north, legend columns=-1, legend     style={/tikz/every even column/.append style={column sep=0.5cm}}}
]
    \addplot coordinates {(1 - 10, 20551) (11 - 100, 19784) (101 - 1000, 2436) (1001 - 10000, 149) (>10000, 12)};
    \addplot coordinates {(1 - 10,4) (11 - 100,4) (101 - 1000,4) (1001 - 10000, 0) (>10000, 0)};
\legend{used,understood,not understood}
\end{axis}
\end{tikzpicture}

电流输出: 电流输出

想要的输出: 期望输出

答案1

您可以将legend其置于0.5代表每个轴中点的位置(无单位)。您也可以将其置于图例锚点。

\documentclass[tikz,border=2mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    width=0.8\textwidth,
    ybar,
    enlargelimits=0.15,
    ylabel={\#Pathes},
    ymode=log,
    log ticks with fixed point,
    xlabel={Test},
    symbolic x coords={1 - 10, 11 - 100, 101 - 1000, 1001 - 10000, >10000},
    xtick=data,
    nodes near coords={\pgfmathprintnumber{\pgfplotspointmeta}},
    nodes near coords align={vertical},
    legend style={at={(0.5,-2.75em)},anchor=north, draw=none, anchor=north, legend columns=-1, legend  style={/tikz/every even column/.append style={column sep=0.5cm}}}
]
    \addplot coordinates {(1 - 10, 20551) (11 - 100, 19784) (101 - 1000, 2436) (1001 - 10000, 149) (>10000, 12)};
    \addplot coordinates {(1 - 10,4) (11 - 100,4) (101 - 1000,4) (1001 - 10000, 0) (>10000, 0)};
\legend{used,understood,not understood}
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容