7

My problem is I would like to make a figure in LaTeX, which looks like the picture. It's important that the y-axis is scaled in a similar way as the picture.

try to make this in latex

BTW I'm using Windows, MikTeX and TeXmaker if it makes a difference.

Here is what i have tried so far:

\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}
Paul Gessler
  • 29,607
Soren
  • 93
  • Welcome to TeX.SX! Can you show us what you've tried so far? Ideally in the form of a minimal working example (MWE). Seeing your code (even if it's just a skeleton/starting point) helps us to give solutions relevant/compatible with your workflow. For example, right now, we don't even know if you use a pstricks-based workflow for graphics or a PGF/TikZ-based one. – Paul Gessler Mar 17 '15 at 11:50
  • now there's a link to a tex document (couldn't put it in a box in here - sorry) – Soren Mar 17 '15 at 12:51
  • Soren, thanks for adding the code. I just added your code to the post for you. We like to keep everything on this site so that it's always accessible. To add code, you can't attach a file, which is probably what you tried. Just copy the code and paste it into your post. I used the code button (looks like { } at the top of the editor box) to format the code in the grey box. – Paul Gessler Mar 17 '15 at 12:59

1 Answers1

6

I think you can massage the following further to make it look like an exact match with fonts etc. I think they mean log base 2 instead of 10 or natural log.

\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}

enter image description here

percusse
  • 157,807
  • @percusse: You could replace yticklabels={1,2,4,8,16,32,64,128,256,512,1024,2048,4096} with yticklabel={\pgfkeys{/pgf/fpu=true}\pgfmathparse{2^\tick}\pgfmathprintnumber[1000 sep={}]{\pgfmathresult}} to get the same result. Not sure if that's better, though, but at least it's not a hand-written list =) – Jake Mar 17 '15 at 15:25
  • 1
    @Jake Yep. I saw that and felt the same :) But since everybody is playing 2048 like crazy I thought they are easy to type ;). – percusse Mar 17 '15 at 15:28