使用不同的数据重新创建 pgfplots 示例,其中某一列的格式为 2^x

使用不同的数据重新创建 pgfplots 示例,其中某一列的格式为 2^x

我正在尝试重新创建这个 pgfplots 图表包含不同的数据。表中没有“深度”,而是“非终端计数”或nts简称,我希望 a 轴值为 2^x 数字格式,而不是 x(当前为 x)。“节点”列仍在那里。

这是我的尝试

在此处输入图片描述

\documentclass[12pt,titlepage]{report}

\usepackage[T1]{fontenc}
\usepackage{pgfplots}\pgfplotsset{compat=newest}
\usetikzlibrary{shapes.symbols}% for starburst
\usepackage{pgfplotstable}

\begin{document}

% JastAdd crashed at size 2^13
\pgfplotstableread{
nts  Nodes    ApsTime       ApsMemory        JastAddTime        JastAddMemory
8      17045        0.6    78     0.8     63
9      67244       2.3    137     2.8     126
10      265762      9.3    479     15     388
11      1024167      72    1288     127     2793
12      3596625     246    5052    983     11073
13      9075268     861    14362    nan       nan
}\followdata


\begin{figure}[htbp]
\centering
\begin{tikzpicture}[
    slanted blocks/.style={
        draw, fill=white, font=\tiny\ttfamily, rotate=45,
        anchor=south west, inner sep=2pt
    }]
    \begin{axis}[
        axis line style = {thick, gray},
        ymode = log,
        ymin = .2,
        xtick = {8,9,...,13},
        xlabel = {Non-terminal count},
        ylabel = {Time (seconds)},
        legend style = {nodes={right, font=\scriptsize},
            at={(0.05,0.9)}, anchor=west},
        clip mode = individual,
        grid = major,
        label style={font=\tiny},
        tick label style={font=\tiny}
        ]
        \addplot table[x=nts, y=JastAddTime]{\followdata};
        \addplot table[x=nts, y=ApsTime]{\followdata};
        \legend{JastAdd, APS}
        \pgfplotsinvokeforeach{8,9,...,12}{
            \node[slanted blocks] at ({#1+1},.2)
                {\pgfplotstablegetelem{#1}{Nodes}\of{\followdata}\pgfplotsretval};
        }
        \node[slanted blocks] at (7.1,.2) {\# of nodes};
        \node[starburst, fill=yellow, draw=red, thick, font=\tiny\ttfamily,
            inner sep=0pt, starburst point height=6pt]
            at (12.5, 2000) {crash!};
    \end{axis}
\end{tikzpicture}

\end{figure}


\end{document}

答案1

我不确定我是否理解正确。您在寻找xticklabel选项吗?您可以在(当前)pgfplots手册的第 343 页找到它。

\documentclass[12pt,titlepage]{report}

\usepackage[T1]{fontenc}
\usepackage{pgfplots}\pgfplotsset{compat=newest}
\usetikzlibrary{shapes.symbols}% for starburst
\usepackage{pgfplotstable}

\begin{document}

% JastAdd crashed at size 2^13
\pgfplotstableread{
nts  Nodes    ApsTime       ApsMemory        JastAddTime        JastAddMemory
8      17045        0.6    78     0.8     63
9      67244       2.3    137     2.8     126
10      265762      9.3    479     15     388
11      1024167      72    1288     127     2793
12      3596625     246    5052    983     11073
13      9075268     861    14362    nan       nan
}\followdata

\begin{figure}[htbp]
\centering
\begin{tikzpicture}[
    slanted blocks/.style={
        draw, fill=white, font=\tiny\ttfamily, rotate=45,
        anchor=south west, inner sep=2pt
    }]
    \begin{axis}[
        axis line style = {thick, gray},
        ymode = log,
        ymin = .2,
        xtick = {8,9,...,13},
        xlabel = {Non-terminal count},
        ylabel = {Time (seconds)},
        legend style = {nodes={right, font=\scriptsize},
            at={(0.05,0.9)}, anchor=west},
        clip mode = individual,
        grid = major,
        label style={font=\tiny},
        tick label style={font=\tiny},
        %%% Added: how to create the ticks, manual page 343 "Tick Options"
        xticklabel={$2^{\pgfmathprintnumber{\tick}}$},
        ]
        \addplot table[x=nts, y=JastAddTime]{\followdata};
        \addplot table[x=nts, y=ApsTime]{\followdata};
        \legend{JastAdd, APS}
        \pgfplotsinvokeforeach{0,1,...,5}{%%% changed to compile
            \node[slanted blocks] at ({#1+8},.2) %% changed to adjust shift
                {\pgfplotstablegetelem{#1}{Nodes}\of{\followdata}\pgfplotsretval};
        }
        \node[slanted blocks] at (7.1,.2) {\# of nodes};
        \node[starburst, fill=yellow, draw=red, thick, font=\tiny\ttfamily,
            inner sep=0pt, starburst point height=6pt]
            at (12.5, 2000) {crash!};
    \end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

在此处输入图片描述

相关内容