![尝试获取带标签的虚线曲线](https://linux22.com/image/462102/%E5%B0%9D%E8%AF%95%E8%8E%B7%E5%8F%96%E5%B8%A6%E6%A0%87%E7%AD%BE%E7%9A%84%E8%99%9A%E7%BA%BF%E6%9B%B2%E7%BA%BF.png)
您能帮助我获得与下图相同的输出吗?
梅威瑟:
\documentclass[tikz,border=1mm]{standalone}
\begin{document}
\begin{tikzpicture}[scale=1.5]
% both figures
\foreach[count=\ii]\i in {A,B}
{
\begin{scope}[shift={(5*\ii-5,0)}]
\node at (-0.2,3.8) {\bfseries \i.};
\draw[latex-latex] (0,3) node[above] {$y$-tokens} |- (3,0) node[right] {\strut$x$-tokens};
\draw[blue] plot [domain=1/2.75:2.75,samples=101] (\x,1/\x) node[black,right] {$k$};
\draw[densely dotted] (0,1) node[left] {$y$} -| (1,0) node[below] {\strut$x$};
\fill (1,1) circle (0.3mm);
\end{scope}
}
% A figure
\draw[densely dotted] (0,0.5) node[left] {$y+\Delta y$} -| (2,0) node[below] {\strut$x+\Delta x$};
\fill (2,0.5) circle (0.3mm);
% B figure
\begin{scope}[shift={(5,0)}]
\draw[blue,shift={(0.75,0.75)}] plot [domain=1/2:2,samples=101] (\x,1/\x) node[black,right] {$k_\Delta$};
\draw[densely dotted] (0,1.75) node[left] {$y+\Delta y$} -| (1.75,0) node[below] {\strut$x+\Delta x$};
\draw[dashed,->] (0,0) -- (2.5,2.5);
\fill (1.75,1.75) circle (0.3mm);
\end{scope}
\end{tikzpicture}
\end{document}
答案1
我尝试让它尽可能地与基础图像相似。有些东西并没有像我希望的那样,但总体来说还不错(我认为)。
输入
\documentclass[tikz,border=1mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[
scale=1.5,
every node/.style={scale=0.5},
>={Triangle[scale=0.6]}
]
% Drawing the main axis:
\draw[<->] (0,1/0.25) node[above]{$y$} --
(0,0) node[below left]{0} --
(4.5,0) node[right]{$x$};
% Drawing the main function:
\draw[thick] plot[domain=0.28:4.4, samples=200](\x,{1/\x}) node[right]{$k^{0}$};
% Drawing the dotted lines:
\draw[densely dotted, thick] (1,0) node[below]{$x^{0}$} |-
(0,1) node[left]{$y^{0}$};
% Drawing the dashed lines:
\foreach \x in {0.55,1,1.3,2}{
\draw[densely dashed] (0,0) -- (\x,1/\x);
}
% Drawing the points:
\foreach \p in {0.45, 0.55, 1, 1.3, 2, 2.6}{
\draw[fill=black] (\p,1/\p) circle (1pt);
}
% Labeling the points:
\node[above right] (M'') at (0.45,1/0.45){$M''$};
\node[above right] (A) at (0.55,1/0.55){$A$};
\node[above right] at (1,1){$P$};
\node[above right] at (1.3,1/1.3){$M$};
\node[above right] (B) at (2,1/2){$B$};
\node[above right] (M') at (2.6,1/2.6){$M'$};
% Drawing the arrows:
\draw[->] (A) -- (M'');
\draw[->] (B) -- (M');
\draw[->] (0.4,3.2) -- (0.55,3.2);
\draw[->] (3.5,0.45) -- (3.65,0.45);
% Drawing the dashed function:
\draw[ thick,
xshift = 0.3cm,
yshift = 0.3cm,
dash pattern = on 10.85pt off 3pt
] plot[domain=0.28:4.4, samples=200](\x,{1/\x}) node[right]{$k^{1}$};
\end{tikzpicture}
\end{document}
输出
答案2
作为起点:
\documentclass[margin=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[scale=1.5,
arr/.style = {-{Triangle[scale=0.8]}, shorten <=2mm, shorten >=2mm},
dot/.style = {circle, fill, inner sep=1pt,
label=above right:#1,
node contents={}},
samples=101
]
% axis
\draw[latex-latex] (0,3) node[above] {$y$} |- (3,0) node[right] {$x$};
% curve k0
\draw[blue, thick]
plot [domain=1/2.75:2.75] (\x,1/\x) node[black,right] {$k^0$};
% curve k1
\draw[blue,thick, dashed,
transform canvas = {shift={(0.75,0.75)}}]
plot [domain=1/2.25:2.25] (\x,1/\x) node[black,right] {$k^1$};
% coordinate x^0, y^0
\draw[densely dotted] (0,1) node[left] {$y^0$} -| (1,0) node[below] {$x^0$};
\fill (1,1) circle (0.3mm);
% rays
\draw[densely dashed] (0,0) node[below left] {$O$}
-- (0.75,1/0.75) node (a) [dot=$A$]
(0,0) -- (1.00,1/1.00) node (p) [dot=$P$]
(0,0) -- (1.25,1/1.25) node (m) [dot=$M$]
(0,0) -- (1.75,1/1.75) node (b) [dot=$B$];
\path (0.5,1/0.5) node (m'') [dot=$M''$]
(2.5,1/2.5) node (m') [dot=$M'$];
\draw[arr, transform canvas = {shift={(0.1,0.1)}}] (a) -- (m'');
\draw[arr, transform canvas = {shift={(0.1,0.1)}}] (b) -- (m');
\end{tikzpicture}
\end{document}
答案3
仅供比较,以下是使用元帖子。
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
path xx, yy, ff, k[];
xx = 20 left -- 300 right;
yy = xx rotated 90;
ff = (1, 1) {dir -45} for x = 2 upto 5: .. (x, 1/x) endfor;
ff := reverse ff reflectedabout(origin, (1,1)) & ff;
k0 = ff scaled 280/5;
k1 = subpath (2, 6) of ff scaled 280/3;
pair A, B, P, M, M', M'';
A = point 3 of k0;
P = point 4 of k0;
M = point 4.5 of k0;
B = point 5.2 of k0;
M' = point 6 of k0;
M'' = point 2.1 of k0;
draw (xpart P, 0) -- P -- (0, ypart P) dashed withdots scaled 1/4;
drawarrow xx;
drawarrow yy;
draw k0 withcolor 2/3 red;
draw k1 withcolor 2/3 red dashed evenly scaled 2;
vardef path_alongside(expr P, t, r, s) =
subpath (t-r, t+r) of P shifted (s * unitvector(direction t of P rotated 90))
enddef;
ahangle := 30;
drawarrow path_alongside(k0, 5.67, 0.2, 6) withcolor 1/2 blue;
drawarrow path_alongside(k0, 2.5, -0.3, 6) withcolor 1/2 blue;
for t = 1, 7:
drawarrow point t of k0 -- point 1/2 t of k1
cutbefore fullcircle scaled 12 shifted point t of k0
cutafter fullcircle scaled 12 shifted point 1/2 t of k1
withcolor 1/2 red;
endfor
forsuffixes $ = A, B, P, M:
draw origin -- $ dashed evenly withpen pencircle scaled 1/4;
endfor
forsuffixes $ = A, B, P, M, M', M'':
dotlabel.urt("$" & str $ & "$", $);
endfor
label.lft("$y^0$", (0, ypart P));
label.bot("$x^0$", (xpart P, 0));
dotlabel.llft("$0$", origin);
label.rt("$k^0$", point 8 of k0);
label.rt("$k^1$", point 8 of k1);
label.rt("$x$", point 1 of xx);
label.top("$y$", point 1 of yy);
endfig;
\end{mplibcode}
\end{document}
这已经结束了luamplib
,因此您需要用 来编译它lualatex
。