梅威瑟:
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
axis lines=center,
axis line style = thick,
xlabel={ $x$ reserves},
ylabel={ $y$ reserves},
x label style={at={(ticklabel cs:0.5)}, anchor=north},
y label style={at={(ticklabel cs:0.5)}, anchor=south, rotate=90},
xmin=0.5, xmax=5,
ymin=0.1, ymax=1,
ticks=none,
enlargelimits=false,
clip=false,
%
domain=1:5,
samples=50,
no marks
]
\addplot [black,thick]{1/x};
\node[circle, fill, inner sep=1pt, label={45:{$(x_b,y_b)$}}] (a) at (6/5,5/6) {};
\node[circle, fill, inner sep=1pt, label={45:{$(x_m,y_m)$}}] (b) at (2,1/2) {};
\node[circle, fill, inner sep=1pt, label={45:{$(x_a,y_a)$}}] (c) at (4,1/4) {};
\draw[ densely dotted] (a) -- (a |- b);
\draw[black] (a |- b) -- (b) node[pos=.33, below] {$x_r$};
\draw[ densely dotted] (c) -- (b |- c);
\draw[black] (b |- c) -- (b) node[pos=.33, left] {$y_r$};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
直接用 Ti 绘制该图形的各个部分可能会更容易钾Z.为了方便调整,我在tikzpicture的开头对两个点的x坐标做了定义。
\documentclass{article}
\usepackage{tikz}
\tikzset{dot/.style={fill, circle, inner sep=0pt, minimum size=4pt}}
\begin{document}
\begin{tikzpicture}[declare function={f(\x)=5/\x; df(\x)=(f(\x+.01)-f(\x-.01))/.02;}, font=\small]
\def\xone{1.8} % x-coordinate of point 1
\def\xzero{3.8} % x-coordinate of point 0
\draw (0,5)node[left]{$R_{\beta}$}--(0,0)--(5.5,0)node[below]{$R_{\alpha}$}; % axis
\draw[very thick, orange] (1,{f(1)}) node[below right]{$R_{\alpha}R_{\beta}=k$}--plot[domain=1:5] (\x,{f(\x)}); % curve
\draw[densely dashed](\xone,0)node[below]{$R_{\alpha}1$}|-(0,{f(\xone)})node[left]{$R_{\beta}1$};
\draw[densely dashed](\xzero,0)node[below]{$R_{\alpha}0$}|-(0,{f(\xzero)})node[left]{$R_{\beta}0$};
\draw([shift={(-2,{-2*df(\xzero)})}]\xzero,{f(\xzero)})--([shift={(1.5,{1.5*df(\xzero)})}]\xzero,{f(\xzero)}); % tangent line
\draw(\xone,{f(\xone)})node[dot, label={[label distance=-4pt]45:Post trade}]{}--(\xzero,{f(\xzero)})node[dot, label={[label distance=-4pt]45:Pre trade}]{};
\end{tikzpicture}
\end{document}
下面是 x₁ 设置为 1.3 且 x₀ 设置为 3.2 的示例。您可以通过更改选项来调整切线的长度shift
。-2
向左延伸 2 个单位,1.5
向右延伸 1.5 个单位。
答案2
答案3
可以使用declare function
和计算数值导数。当然,在这种情况下,数值导数可以用解析函数代替。declare function
也可以用来定义x_a
、x_m
和x_b
。这样,你只需要更改一次,而不必在代码的各个位置进行更改。切线也可以用这种方式定义。结果如下:
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}[declare function={f(\x)=1/\x;
dx=0.01;
fprime(\x)=(f(\x+dx)-f(\x-dx))/(2*dx);
tangent(\x,\y)=f(\y)+fprime(\y)*(\x-\y);
xb=6/5;xm=2;xa=4;
}]
\begin{axis}[%
axis lines=center,
axis line style = thick,
xlabel={ $x$ reserves},
ylabel={ $y$ reserves},
x label style={at={(ticklabel cs:0.5)}, anchor=north},
y label style={at={(ticklabel cs:0.5)}, anchor=south, rotate=90},
xmin=0.5, xmax=5,
ymin=0.1, ymax=1,
ticks=none,
enlargelimits=false,
clip=false,
%
domain=1:5,
samples=50,
no marks
]
\addplot [black,thick]{f(x)};
\addplot [blue,thick,domain=xa-2:xa+1.2]{tangent(x,xa)};
\addplot [purple,thick,domain=xm-1:xm+1]{tangent(x,xm)};
\addplot [red,thick,domain=xb-0.25:xb+0.25]{tangent(x,xb)};
\node[circle, fill, inner sep=1pt, label={45:{$(x_b,y_b)$}}] (a) at (xb,{f(xb)}) {};
\node[circle, fill, inner sep=1pt, label={45:{$(x_m,y_m)$}}] (b) at (xm,{f(xm)}) {};
\node[circle, fill, inner sep=1pt, label={45:{$(x_a,y_a)$}}] (c) at (xa,{f(xa)}) {};
\draw[ densely dotted] (a) -- (a |- b);
\draw[black] (a |- b) -- (b) node[pos=.33, below] {$x_r$};
\draw[ densely dotted] (c) -- (b |- c);
\draw[black] (b |- c) -- (b) node[pos=.33, left] {$y_r$};
\end{axis}
\end{tikzpicture}
\end{document}
答案4
使用tzplot:
\documentclass[border=3pt]{standalone}
\usepackage{tzplot}
\begin{document}
\begin{tikzpicture}[scale=1.4]
\settzdotsize{4pt}
\tzhelplines(0,0)(5,5)
\tzaxes*(0,0)(5,5.5){$R_\alpha$}[b]{$R_\beta$}[l]
\def\Fx{5/\x}
\tzfn[very thick,orange]\Fx[5:1]{$R_\alpha R_\beta=k$}[br,orange]
\tzvXpointat*{Fx}{1.8}(P0){Post trade}[ar]
\tzvXpointat*{Fx}{3.8}(P1){Pre trade}[ar]
\tzline(P0)(P1)
\tztangent{Fx}(P1)[1.8:5.3]
\tzproj[dashed](P0){$R_\alpha0$}{$R_\beta0$}
\tzproj[dashed](P1){$R_\alpha1$}{$R_\beta1$}
\end{tikzpicture}
\end{document}