我想在 latex 中画一幅画,就像下面的图片一样。我尝试学习 pgfmanual,但我不知道该怎么做。有人能帮我吗?
\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}
答案1
这是一个起点pgfplots
及其fillbetween
图书馆:
代码:
\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}
或者,使用该patterns
库,您可以获得更接近原始图像的东西:
\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}