pgfplots:在一个对数轴上用固定点对数刻度

pgfplots:在一个对数轴上用固定点对数刻度

我有一个带有两个对数轴的图表,但我希望将其中一个轴的标签设置为以定点格式显示。这可能吗?下面是如何使用定点格式获取两个轴的最小示例。我希望 x 轴是定点。

\begin{figure}[H]
\centering
\begin{tikzpicture}
    \begin{loglogaxis}[
        xlabel=Processes,
        ylabel=Run time (Seconds)
        log ticks with fixed point
    ]
    \addplot[mark=*,blue] plot coordinates {
        (1,0.005584)
        (2,0.003083)
        (4,0.001586)
        (8,0.006259)
    };
    \addlegendentry{100000}

    \addplot[color=red,mark=x]
        plot coordinates {
            (1,0.036002)
            (2,0.024381)
            (4,0.014283)
            (8,0.008018)
        };
    \addlegendentry{1000000}

    \addplot[color=green,mark=o]
        plot coordinates {
            (1,0.334952)
            (2,0.178412)
            (4,0.092895)
            (8,0.053607)
        };
    \addlegendentry{10000000}
    \end{loglogaxis}
\end{tikzpicture}
\caption{Number of processes against run time}
\end{figure}

答案1

在这种情况下,您不应使用log ticks with fixed point样式,而应将 x 轴刻度标签的格式设置为类似 的格式xticklabel=\pgfmathparse{exp(\tick)}\pgfmathprintnumber{\pgfmathresult},这将评估指数表达式并打印定点数。但请注意,这会导致奇怪的刻度值:

对于您的数据,您应该将 x 轴的对数基设置为log basis x=2,并将刻度标签设置为xticklabel=\pgfmathparse{2^\tick}\pgfmathprintnumber{\pgfmathresult}

\documentclass[]{article}
\usepackage{filecontents,pgfplots}

\begin{document}
\begin{tikzpicture}
    \begin{loglogaxis}[
        xlabel=Processes,
        ylabel=Run time (Seconds),
        log basis x=2,
        xticklabel=\pgfmathparse{2^\tick}\pgfmathprintnumber{\pgfmathresult}
    ]
    \addplot[mark=*,blue] plot coordinates {
        (1,0.005584)
        (2,0.003083)
        (4,0.001586)
        (8,0.006259)
    };
    \addlegendentry{100000}

    \addplot[color=red,mark=x]
        plot coordinates {
            (1,0.036002)
            (2,0.024381)
            (4,0.014283)
            (8,0.008018)
        };
    \addlegendentry{1000000}

    \addplot[color=green,mark=o]
        plot coordinates {
            (1,0.334952)
            (2,0.178412)
            (4,0.092895)
            (8,0.053607)
        };
    \addlegendentry{10000000}
    \end{loglogaxis}
\end{tikzpicture}

\end{document}

相关内容