如何在乳胶中制作一个显示函数增长但带有缩放 y 轴的图形?

如何在乳胶中制作一个显示函数增长但带有缩放 y 轴的图形?

我的问题是我想用 LaTeX 制作一个看起来像图片的图形。重要的是 y 轴的缩放方式与图片类似。

尝试用乳胶制作

顺便说一句,如果有什么区别的话,我会使用 Windows、MikTeX 和 TeXmaker。

以下是我迄今为止尝试过的:

\documentclass[12pt,a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
\begin{figure}
    \begin{tikzpicture}[yscale=0.17]
        \draw [help lines, <->] (2,0) -- (8,0);
        \draw [help lines, ->] (2,35) -- (2,0);
            \draw [blue,domain=2:4.9]       plot (\x, {factorial(\x)})  node[right]{$n!$};
            \draw [blue,domain=2:5]         plot (\x, {pow(2,\x})       node[right]{$2^n$};
            \draw [blue,domain=2:6]         plot (\x, {pow(\x,2})       node[right]{$n^2$};
            \draw [red, domain=2:8]         plot (\x, {\x*log10(\x)})   node[right]{$nlog(n)$};
            \draw [green,domain=2:8]        plot (\x, {\x})             node[right]{$n$};
            \draw [blue,domain=2:8]         plot (\x, {log10(\x)})      node[right]{$log(n)$};
            \draw [black,domain=2:8]        plot (\x, {1})              node[right]{$1$};
    \end{tikzpicture}
\end{figure}

\begin{figure}
    \begin{tikzpicture}
    \begin{axis}[title=Random Dataset,
            ytick={1,2,4,8,16,32,64,128,256,512,1024,2024,4096}, % new bit
            scaled ticks=true,
            axis x line=bottom,
            axis y line=left,
            axis line style=-,
            enlargelimits,
            ylabel = Solving Time (ms),
            xlabel = Service Class Size,
            ymode=log,
        ]
%       \draw [help lines, <->] (2,0) -- (8,0);
%       \draw [help lines, ->] (2,35) -- (2,0);
            \draw [blue,domain=1:4.9]       plot (\x, {factorial(\x)})  node[right]{$n!$};
            \draw [blue,domain=0:5]         plot (\x, {pow(2,\x})       node[right]{$2^n$};
            \draw [blue,domain=1:6]         plot (\x, {pow(\x,2})       node[right]{$n^2$};
            \draw [red, domain=1:8]         plot (\x, {\x*log10(\x)})   node[right]{$nlog(n)$};
            \draw [green,domain=0:8]        plot (\x, {\x})             node[right]{$n$};
            \draw [blue,domain=1:8]         plot (\x, {log10(\x)})      node[right]{$log(n)$};
            \draw [black,domain=0:8]        plot (\x, {1})              node[right]{$1$};
    \end{axis}  
    \end{tikzpicture}
\end{figure}
\end{document}

答案1

我认为您可以进一步修改以下内容,使其看起来与字体等完全匹配。我认为它们的意思是以 2 为底的对数,而不是 10 或自然对数。

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{semilogyaxis}[title=Random Dataset,height=10cm,width=9cm,
        scaled ticks=false,
        log ticks with fixed point,
        axis lines=left,
        axis line style=-,
        enlargelimits={upper=0.3},
        ylabel = Solving Time (ms),
        xlabel = Service Class Size,
        ymin=0.5,ymax=4096,xmin=2,xmax=8,domain=2:8,
        log basis y =2,ytickten={0,...,12},
        yticklabels={1,2,4,8,16,32,64,128,256,512,1024,2048,4096},
    ]
        \addplot [blue,samples at={2,...,8}] {factorial(x)}  node[left,pos=0.75]{$n!$};
        \addplot [blue] {pow(2,x)}       node[above left]{$2^n$};
        \addplot [blue] {x^2}           node[above left]{$n^2$};
        \addplot [blue] {x*(ln(x)/ln(2))}       node[above left]{$n\log(n)$};
        \addplot [blue] {x}             node[above left]{$n$};
        \addplot [blue] {ln(x)/ln(2)}         node[above left]{$\log(n)$};
        \addplot [blue] {1}             node[above left]{$1$};
\end{semilogyaxis}  
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容