I'm trying to replicate this graph following the tips in this solution with TikZ datavisualization package (see Part VI).
[edit] related question: How to make a figure showing growth of functions but with scaled y-axis?
This is the desired output:
bonus: it would be wonderful if it would be possible to reproduce this graph adding colored regions.
This is my output:
I have two problems that I don't know how to resolve:
- I have to manually compute the values at which to stop the
xof the functionsx^2,2^n,x!because otherwise they will overflow from the top edge; - I don't know how to invoke the
Gammafunction to plot the factorial on real numbers as suggested here, also I'm typesetting this document on Windows and my colleagues are on linux, so the solution has to be cross-platform (without usinggnuplot).
This is what I've done so far:
\documentclass[border=2mm,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{datavisualization}
\usetikzlibrary{datavisualization.formats.functions}
\pgfkeys{/pgf/number format/.cd, use comma, set thousands separator={\,}}
\begin{document}
\begin{tikzpicture}
\datavisualization [scientific axes=inner ticks,
style sheet=strong colors,
x axis={label={\textbf{\textsf{Elements}}}, length=8cm, min value=0, max value=100},
y axis={label={\textbf{\textsf{Operations}}}, length=5cm, min value=0, max value=2500},
data/format=function,
visualize as smooth line/.list={direct, logarithmic, linear, nlogarithmic, quadratic, exponential, factorial},
direct={label in legend={text=$\mathcal{O}(1)$}},
logarithmic={label in legend={text=$\mathcal{O}(\log n)$}},
linear={label in legend={text=$\mathcal{O}(n)$}},
nlogarithmic={label in legend={text=$\mathcal{O}(n \log n)$}},
quadratic={label in legend={text=$\mathcal{O}(n^2)$}},
exponential={label in legend={text=$\mathcal{O}(2^n)$}},
factorial={label in legend={text=$\mathcal{O}(n!)$}},
]
data [set=direct] {
var x : interval [0:100];
func y = 1;
}
data [set=logarithmic] {
var x : interval [1:100];
func y = ln(\value x);
}
data [set=linear] {
var x : interval [0:100];
func y = \value x;
}
data [set=nlogarithmic] {
var x : interval [1:100];
func y = (\value x) * ln(\value x);
}
data [set=quadratic] {
var x : interval [0:50];
func y = \value x^2;
}
data [set=exponential] {
var x : interval [0:11];
func y = 2^(\value x);
}
data [set=factorial] {
var x : interval [0:7];
func y = factorial(\value x);
};
\end{tikzpicture}
\end{document}



restrict y to domain=ymin:ymaxin theaxisenvironment to set the borders of your plot – Excelsior Apr 15 '21 at 17:25