我目前正在嘗試創建一個圖表,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}