
저는 tikz와 pgf를 처음 접했습니다. 저는 Big O 시간 복잡도를 계획하고 있으며 충분한 예제를 살펴본 후 계승을 제외하고 제가 원하는 그래프를 정확하게 만들 수 있었습니다. 간단히 x를 그려보세요! 이상한 계단형 그래프가 생성됩니다. 부드러운 곡선이었으면 좋겠어요. 나는 찾았다이 질문using 이라는 답이 있습니다 semilogyaxis
. 그러나 간단히 전환하는 것은 도움이 되지 않으며 계승 그래프는 동일하게 보입니다. 또한 질문의 예제 답변에 따라 완전히 새로운 플롯을 시도했지만 오버레이되었지만 계승 그래프가 올바르지 않은 것처럼 보였습니다. 로그 y축과 관련이 있다고 가정하고 좌표를 조정하는 방법을 잘 모르겠습니다. f(x) = x!
아래와 같은 그래프를 생성하는 것과 같은 것이 필요합니다 .
지금까지 내가 가지고 있는 MWE는 다음과 같습니다.
\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
grid = major,
clip = true,
ticks = none,
width=0.8\textwidth,
height=0.6\textwidth,
every axis plot/.append style={very thick},
axis line style = ultra thick,
clip mode=individual,
restrict y to domain=0:10,
restrict x to domain=0:10,
axis x line = left,
axis y line = left,
domain = 0.00:10,
xmin = 0,
xmax = 11,
ymin = 0,
ymax = 11,
xlabel = n,
ylabel = no. of operations,
xlabel style = {at={(axis description cs:0.5,-0.1)},anchor=south},
ylabel style = {at={(axis description cs:-0.08,0.5)},anchor=north},
label style = {font=\LARGE\bf},
]
\addplot [
samples=100,
color=red,
]
{x^2}node[above,pos=1,style={font=\Large}]{$\mathcal{O}(n^2)$};
\addplot [
samples=100,
color=blue,
]
{x}node[above,pos=1,style={font=\Large}]{$\mathcal{O}(n)$};
\addplot [
samples=100,
color=orange,
]
{log2 x}node[above,pos=1,style={font=\Large}]{$\mathcal{O}(\log{}n)$};
\addplot [
samples=100,
color=black,
]
{x*(log2 x)}node[above,pos=1,style={font=\Large}]{$\mathcal{O}(n\log{}n)$};
\addplot [
samples=100,
color=magenta,
]
{1}node[above,pos=1,style={font=\Large}]{$\mathcal{O}(1)$};
\addplot [
samples=100,
color=cyan,
]
{x^3}node[above,pos=1,style={font=\Large}]{$\mathcal{O}(n^3)$};
%Creates stair-step like plot
\addplot [
samples=100,
color=green,
]{x!}node[above,pos=1,style={font=\Large}]{$\mathcal{O}(n!)$};
\end{axis}
\end{tikzpicture}
\end{document}
다음 플롯이 생성됩니다.
답변1
@haver 솔루션을 다시 만듭니다.https://tex.stackexchange.com/a/520121/8650OP 코드가 포함된 감마 함수 - 사람들이 연속 계승을 검색하는 데 도움이 됩니다. 실수 계승은 정수에 대해서만 정의됩니다. 참조https://en.wikipedia.org/wiki/Factorial.x! = Γ(x + 1)
이 솔루션에는 다음이 필요 gnuplot
합니다 --shell-escape
.
\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
grid = major,
clip = true,
ticks = none,
width=0.8\textwidth,
height=0.6\textwidth,
every axis plot/.append style={very thick},
axis line style = ultra thick,
clip mode=individual,
restrict y to domain=0:10,
restrict x to domain=0:10,
axis x line = left,
axis y line = left,
domain = 0.00:10,
xmin = 0,
xmax = 11,
ymin = 0,
ymax = 11,
xlabel = n,
ylabel = no. of operations,
xlabel style = {at={(axis description cs:0.5,-0.1)},anchor=south},
ylabel style = {at={(axis description cs:-0.08,0.5)},anchor=north},
label style = {font=\LARGE\bf},
]
\addplot [
samples=100,
color=red,
]
{x^2}node[above,pos=1,style={font=\Large}]{$\mathcal{O}(n^2)$};
\addplot [
samples=100,
color=blue,
]
{x}node[above,pos=1,style={font=\Large}]{$\mathcal{O}(n)$};
\addplot [
samples=100,
color=orange,
]
{log2 x}node[above,pos=1,style={font=\Large}]{$\mathcal{O}(\log{}n)$};
\addplot [
samples=100,
color=black,
]
{x*(log2 x)}node[above,pos=1,style={font=\Large}]{$\mathcal{O}(n\log{}n)$};
\addplot [
samples=100,
color=magenta,
]
{1}node[above,pos=1,style={font=\Large}]{$\mathcal{O}(1)$};
\addplot [
samples=100,
color=cyan,
]
{x^3}node[above,pos=1,style={font=\Large}]{$\mathcal{O}(n^3)$};
%Creates stair-step like plot
\addplot [
samples=100,
color=green,
]{x!}node[above,pos=1,style={font=\Large}]{$\mathcal{O}(n!)$};
\addplot [
samples=100,
color=green,
] gnuplot{gamma(x+1)} node[above,pos=1,style={font=\Large}]{$\mathcal{O}(n!)$};
\end{axis}
\end{tikzpicture}
\end{document}