我想在 LaTeX 中制作一个类似于下图的图(通过 TikZ 或其他工具)。我已经找到了一种绘制布朗路径的方法。但是,我不知道如何添加下图所示的虚线。这些线是在布朗路径达到特定值时生成的,标签将是字母而不是数字。谢谢!
实际上,我找到的绘制布朗路径的方法在这里: 如何在 tikz/pgf 中绘制布朗运动
我不需要像该链接中的答案那样添加上限或下限。但是,我确实需要为某些特定值添加一些虚线。
答案1
以下是使用元帖子包裹在luamplib
。使用 进行编译lualatex
,请点击链接获取更多详细信息。
\RequirePackage{luatex85}
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
% set a seed, so it is repeatable (it will work fine if you
% delete this, but you will get a different path...)
randomseed := 1288.27463;
numeric a, u, v, wt, N, hi, lo;
% parameters
a = 0;
N = 100;
lo = -hi = infinity;
wt = 2/5; % weight - larger = more random
% scales
u = 1mm; % scale
v = 1cm;
% make the brownian path, keeping track of the hi and lo points
% you could use uniformdeviate or calculate a more complicated
% distribution here instead of "normaldeviate"
path A;
A = (origin for t=1 upto N:
hide(
if a>hi: hi := a; fi if a<lo: lo := a; fi
a := a + wt * normaldeviate;
)
-- (t,a)
endfor) xscaled u yscaled v;
% draw in the axes nicely
drawoptions(withcolor 1/2 white);
draw ((0,lo)--(0,hi)) scaled v;
for i=ceiling(lo) upto floor(hi) :
draw (left--right) scaled 2 shifted (0,i*v);
label.lft("$" & decimal i & "$", (0,i*v));
endfor
draw (origin--right) scaled (N*u);
% draw the markers at the desired points along the brownian motion path
drawoptions(dashed evenly scaled 1/2 withcolor 2/3 blue);
z0 = point 44 of A;
draw (x0,-16) -- z0 -- (-16,y0);
label.bot("$T_0$", (x0,-16));
label.lft("$M_0$", (-16,y0));
z1 = point 81 of A;
draw (x1,-16) -- z1 -- (-16,y1);
label.bot("$T_1$", (x1,-16));
label.lft("$M_1$", (-16,y1));
% etc...
% finally draw the path on top of everything else
drawoptions(withcolor 2/3 red);
draw A;
drawoptions();
endfig;
\end{mplibcode}
\end{document}