![PGFPlots x 轴的对数缩放和以 2 为底的刻度](https://linux22.com/image/398700/PGFPlots%20x%20%E8%BD%B4%E7%9A%84%E5%AF%B9%E6%95%B0%E7%BC%A9%E6%94%BE%E5%92%8C%E4%BB%A5%202%20%E4%B8%BA%E5%BA%95%E7%9A%84%E5%88%BB%E5%BA%A6.png)
我正在尝试创建一个图,其中 x 轴缩放到底数为 2,刻度应位于坐标的准确高度。我有对数 x 轴,但我无法让刻度位于坐标的位置。此外,刻度应采用 2^14、2^15 等形式,而不是 0.1*10^6 等。目前我的图由以下代码制作:
\begin{figure}[h]
\begin{tikzpicture}
\begin{axis}[xlabel=n,ylabel=used time in ms,xmode=log]
\addplot coordinates{ (2^14, 8) (2^15, 26) (2^16, 72) (2^17, 185) (2^18, 414) (2^19,956) (2^20,2017) };
\addplot coordinates{ (2^14, 9) (2^15, 28) (2^16, 73) (2^17, 195) (2^18, 441) (2^19,1032) (2^20,2155) };
\addplot coordinates{ (2^14, 8) (2^15, 23) (2^16, 65) (2^17, 175) (2^18, 406) (2^19,937) (2^20,2189) };
\addplot coordinates{ (2^14, 10) (2^15, 30) (2^16, 83) (2^17, 229) (2^18, 536) (2^19,1216) (2^20,2669) };
\addplot coordinates{ (2^14, 8) (2^15, 24) (2^16, 64) (2^17, 177) (2^18, 412) (2^19,960) (2^20,2045) };
\end{axis}
\end{tikzpicture}
\end{figure}
目前,它看起来像下图一样。
但它看起来应该是这样的,但是用的是 2^14,2^15,.. 而不是 14,15,... 。我通过在坐标中省略基数来绘制此图。
答案1
欢迎来到 TeX-SE!您在寻找吗log basis x=2
?
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel=$n$,ylabel=used time in ms,xmode=log,log basis x=2]
\addplot coordinates{ (2^14, 8) (2^15, 26) (2^16, 72) (2^17, 185) (2^18, 414) (2^19,956) (2^20,2017) };
\addplot coordinates{ (2^14, 9) (2^15, 28) (2^16, 73) (2^17, 195) (2^18, 441) (2^19,1032) (2^20,2155) };
\addplot coordinates{ (2^14, 8) (2^15, 23) (2^16, 65) (2^17, 175) (2^18, 406) (2^19,937) (2^20,2189) };
\addplot coordinates{ (2^14, 10) (2^15, 30) (2^16, 83) (2^17, 229) (2^18, 536) (2^19,1216) (2^20,2669) };
\addplot coordinates{ (2^14, 8) (2^15, 24) (2^16, 64) (2^17, 177) (2^18, 412) (2^19,960) (2^20,2045) };
\end{axis}
\end{tikzpicture}
\end{document}