2

I want to make a plot that look similar to the one below in LaTeX (through either TikZ or something else). I have already found a method to plot the Brownian path. However, I do not know how to add the dashed lines shown in the picture below. These lines are made when the Brownian path hits a particular value and the labels will be letters rather than numbers. Thank you!

An Example

Actually, the method to plot the Brownian path I found is here: How to draw Brownian motions in tikz/pgf

I don't need to add upper bound or lower bound as in the answers in that link. But, I do need to add some dashed lines for some particular values.

  • 1
    Can you show us the code you have for the plot without the dashed lines? – Torbjørn T. Apr 26 '17 at 18:55
  • Please add the code for plotting the Brownian path. The way how to draw the dashed lines depends on the way how you draw the graph. – gernot Apr 26 '17 at 18:55
  • May be you can save the brownian path inside a pgfplotstable (like in tex.stackexchange.com/a/60370/1952) and read the values from it. – Ignasi Apr 26 '17 at 19:20
1

Here's an attempt using Metapost wrapped up in luamplib. Compile with lualatex, follow the links for more details.

enter image description here

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.