5

I'd like to draw a picture in latex, like the image below. I've tried to study the pgfmanual, but i couldn't figure out how to do it. Can anyone help me, please?

\documentclass[margin=2cm]{standalone}
\usepackage{pgfplots}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\draw (-2,0) -- (10,0);
\draw (0,-2) -- (0,10);
\draw (2,0) -- (2,10);
\draw (6,0) -- (6,10);
\node[below right] at (0,0) {Words by rank order};
\node[below right] at (2,10) {Upper cut-off};
\node[below right] at (6,10) {Lover cut off};
\node[above left, rotate=-270] at (0,3.3) {Frequency of words};
\end{tikzpicture}
\end{document}

zipf_curve and luhn_cuts

Amelie B. Blackstone
  • 1,502
  • 1
  • 13
  • 26

1 Answers1

5

Here's a starting point using pgfplots and its fillbetween library:

enter image description here

The code:

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}

\pgfmathdeclarefunction{gauss}{3}{%
  \pgfmathparse{1/(#3*sqrt(2*pi))*exp(-((#1-#2)^2)/(2*#3^2))}%
}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
  no markers, 
  domain=0:7, 
  samples=150,
  ymin=0,
  ymax=1,
  axis lines*=left, 
  height=8cm, 
  width=9cm,
  ylabel=Frequency of words,
  xtick=\empty, 
  ytick=\empty,
  enlargelimits=false, 
  axis on top,
  clip=false
]

\addplot[thick,dashed,cyan!50!black] 
  {gauss(x, 3, 1)};
\addplot[red!50!black,domain=0.2:7,name path=curve,restrict y to domain=-inf:1]   
  {1/(4*x)};
\addplot[name path=xaxis] 
  {0};

\addplot[orange!30] 
  fill between[of=curve and xaxis,soft clip={domain=1:5}];

\draw[gray] 
  (axis cs:1,0) -- (axis cs:1,1)
  (axis cs:5,0) -- (axis cs:5,1);

\node[right,align=left,anchor=north west] at (axis cs:1,1)  {Upper \\ cut-off}; 
\node[right,align=left,anchor=north west] at (axis cs:5,1)  {Lower \\ cut-off}; 

\coordinate (aux1) at (axis cs:3.5,{gauss(3.5,3,1)});
\node[align=left,anchor=south west] 
  at ([xshift=0.5cm,yshift=10pt]aux1)
  (respow)
  {Resolving power \\ of significant words};
\draw
  (respow.west) -- (aux1);

\coordinate (aux2) at (axis cs:3.5,{1/(4*3.5)});
\node[align=left,anchor=south west] 
  at ([xshift=0.3cm]aux2)
  (sig)
  {Significant words};
\draw
  (sig.west) -- ([yshift=-4pt]aux2);

\node[anchor=north west] 
  at (axis cs:0,0)
  {Words by rank order};
\end{axis}    
\end{tikzpicture}

\end{document}

Or, using the patterns library you can get something more close to the original image:

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}

\pgfmathdeclarefunction{gauss}{3}{%
  \pgfmathparse{1/(#3*sqrt(2*pi))*exp(-((#1-#2)^2)/(2*#3^2))}%
}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
  no markers, 
  domain=0:7, 
  samples=150,
  ymin=0,
  ymax=1,
  axis lines*=left, 
  height=8cm, 
  width=9cm,
  ylabel=Frequency of words,
  xtick=\empty, 
  ytick=\empty,
  enlargelimits=false, 
  axis on top,
  clip=false
]

\addplot[thick,dashed,cyan!50!black] 
  {gauss(x, 3, 1)};
\addplot[thick,red!50!black,domain=0.2:7,name path=curve,restrict y to domain=-inf:1]   
  {1/(4*x)};
\addplot[name path=xaxis] 
  {0};

\addplot[pattern=crosshatch,opacity=0.5] 
  fill between[of=curve and xaxis,soft clip={domain=1:5}];

\draw[gray] 
  (axis cs:1,0) -- (axis cs:1,1)
  (axis cs:5,0) -- (axis cs:5,1);

\node[right,align=left,anchor=north west] at (axis cs:1,1)  {Upper \\ cut-off}; 
\node[right,align=left,anchor=north west] at (axis cs:5,1)  {Lower \\ cut-off}; 

\coordinate (aux1) at (axis cs:3.5,{gauss(3.5,3,1)});
\node[align=left,anchor=south west] 
  at ([xshift=0.5cm,yshift=10pt]aux1)
  (respow)
  {Resolving power \\ of significant words};
\draw
  (respow.west) -- (aux1);

\coordinate (aux2) at (axis cs:3.5,{1/(4*3.5)});
\node[align=left,anchor=south west] 
  at ([xshift=0.3cm]aux2)
  (sig)
  {Significant words};
\draw
  (sig.west) -- ([yshift=-4pt]aux2);

\node[anchor=north west] 
  at (axis cs:0,0)
  {Words by rank order};
\end{axis}    
\end{tikzpicture}

\end{document}

enter image description here

Gonzalo Medina
  • 505,128