我正在尝试在 LaTeX 中复制下面的图,但我对编码有点迷茫。不需要数学。这只是一个练习,创建类似于指数衰减的通用图。我想复制 y 轴标签,其中 y_0、\frac{y_0}{2} 和 x 轴上的 \tau。
我的尝试
\documentclass{amsart}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepackage{mathtools}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
scaled ticks=false,
xmin=0,
ymin=0,
xlabel=x,
ylabel=y ,
]
\addplot[domain=0:5, black, ultra thick,smooth] {e^(-x)};
\addplot[domain=0:0.7, gray, dashed] {0.5};
\end{axis}
\end{tikzpicture}
答案1
这里有一个例子,尽可能地模仿您的图中的风格。
\documentclass{amsart}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepackage{mathtools}
%\usepackage{tikz} %load by pgfplots
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0,
xmax=2.1,
ymin=0,
ymax=1.3,
tick style={draw=none},
xtick={-ln(0.5)},
ytick={0.5,1},
xticklabels={$\tau$},
xticklabel style={font=\Large},
yticklabels={$\displaystyle\frac{y_0}{2}$,$y_0$},
yticklabel style={font=\Large},
xlabel=$t$,
ylabel=$y$,
axis lines=center,
axis line style ={thick,-latex},
x label style={anchor=west},
y label style={anchor=south}
]
\addplot[domain=0:2, black, ultra thick,smooth] {e^(-x)};
\draw [thick,dotted] (axis cs:0,0.5) -- (axis cs:{-ln(0.5)},0.5) -- (axis cs:{-ln(0.5)},0);
\end{axis}
\end{tikzpicture}
\end{document}
答案2
有了图书馆intersection
\documentclass{amsart}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{intersections}
\usepackage{mathtools}
% \usepackage{tikz}%<-- loaded by pgfplots
\begin{document}
\begin{tikzpicture}
\begin{axis}[
clip=false,
declare function={
f(\x)=e^(-\x);
},
scaled ticks=false,
axis lines=center,
xmin=0,
ymin=0,
xmax=5.2,
ymax=1.2,
xlabel=t,
ylabel=y,
xlabel style={
at={(1,0)},
anchor=west,
},
ylabel style={
at={(0,1)},
align=right,
anchor=south,
},
tick style={draw=none},
xtick=\empty,ytick=\empty,
]
\addplot[name path=curve,domain=0:5, black, ultra thick,smooth] {f(x)};
\path [name path=line] (axis cs:0,0.5) -- (axis cs:5,0.5);
%
\fill [red, opacity=0.5, name intersections={of=line and curve}]
(intersection-1) circle (2pt);
\draw[name intersections={of=line and curve}] [dashed](intersection-1)-|(axis cs:0,0)node[pos=0.5,xshift=-2ex,red]{$\dfrac{y_0}{2}$};
\draw[name intersections={of=line and curve}] [dashed](intersection-1)|-(axis cs:0,0)node[pos=0.5,yshift=-1ex,red]{$\tau$};
%
\node[xshift=-2ex,red]at(axis cs:0,1){$y_0$};
\end{axis}
\end{tikzpicture}
\end{document}
答案3
像这样:
代码 (tikz
):
\documentclass[margin=20pt]{standalone}
\usepackage{tikz}
%\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\draw[gray!30] (0,0) grid (6,6);
\draw[cyan,line width=2pt] plot[domain=0:6,smooth,samples=60] (\x,{6*2^(-\x)});
\draw[-latex] (0,0)--(6,0);
\draw[-latex] (0,0)--(0,6.5);
\foreach \x in {0,1,...,6}
\draw (\x,0)--(\x,-3pt) node[below] () {\small \x$\tau$};
\draw (0,6) node[left] () {$y_0$};
\draw (0,3) node[left] () {$\frac{y_0}{2}$};
\end{tikzpicture}
\end{document}
答案4
和tzplot
:
\documentclass{standalone}
\usepackage{tzplot}
\begin{document}
\begin{tikzpicture}[yscale=2]
\tzaxes(3,1.3){$t$}{$y$}
\def\Fx{exp(-\x)}
\tzfn\Fx[2.5:0]{$y_0$}[l]
\tzvXpointat{Fx}{.8}(X)
\tzproj[densely dotted](X){$\tau$}{$\frac{y_0}{2}$}
\end{tikzpicture}
\end{document}