JeT
I'd like to replace the mark of my plot with a mini brownian diffusion.

I'll probably need to embed it in a pic.

I have the ingredients, I need a little help (some would say I am missing a pi(e)c(e)... ) on the recipe.

I don't look for the version below with one brownian  replicated 5 times and not consistent  with the measure on the main graph.

![MAinplot2.png](/image?hash=545e69920b248944cf8f79ba2abee0d2bd7bcf1be3ecfb4e724fba8e371ae384)

I imagine more something like (Poorly copied pasted) with one brownian per period, whose coordinates are consistent with the main plot.

**Where do I need help ?**

I'd like each brownian
- to start at the mark
- have a width of one tick for the pic
- diffusion being consistent with the main plot grid

Details in the MWE below.


\documentclass[tikz]{standalone}
\usepackage{pgfplots, pgfplotstable}
\usetikzlibrary{positioning}

\tikzset{
declare function={
invgauss(\a,\b) = sqrt(-2*ln(\a))*cos(deg(2*pi*\b));
}
}

%-----------------------------------------------------------------
% Code from Jake @ TeX.SE to generate brownian motions
% If you have an idea to load to improve the compilation time
\makeatletter
\pgfplotsset{
table/.cd,
brownian motion/.style={
create on use/brown/.style={
create col/expr accum={
(\coordindex>0)*(
max(
min(
invgauss(rnd,rnd)*0.25*sqrt(1)+\pgfmathaccuma,
\pgfplots@brownian@max
),
\pgfplots@brownian@min
)
) + (\coordindex<1)*\pgfplots@brownian@start
}{\pgfplots@brownian@start}
},
y=brown, x expr={\coordindex},
brownian motion/.cd,
#1,
/.cd
},
brownian motion/.cd,
min/.store in=\pgfplots@brownian@min,
min=-inf,
max/.store in=\pgfplots@brownian@max,
max=inf,
start/.store in=\pgfplots@brownian@start,
start= 0
}
\makeatother

%-----------------------------------------------------------------
% Create the pic that generates brownian motions
% I did my homework and read the pgfmanual.
% It enabled me to use parameters in pic
% The idea is to have flexibility on the brownian
% \pic{BM=color/Starting@y/nbs of paths/nbs of points in the path};
% "nbs of points in the path" represents the subdivision of 1 unit of time

\tikzset{pics/BM/.style args={#1/#2/#3/#4}{
code = {%
\pgfmathsetseed{3}
\pgfplotstablenew{#4}\wiener % Initialise an empty table with #4 steps for brownians
\node[](#1){
\begin{tikzpicture}
\begin{axis}[
axis line style={draw=none},
tick style={draw=none},
xtick=\empty, ytick=\empty,
% xlabel = subdivision of 1 unit of time,
% ylabel = $S$,
]
\foreach \i in {1,...,#3}{% <- I can draw #3 paths
% start is a paramater to make it start at the mark  on the main plot
%	[brownian motion={start=#2,min=80,max=120}] {\wiener};
% no impact of min and max...
}
\end{axis}
\end{tikzpicture}
};
}}}

\begin{document}

% Main plot
\begin{tikzpicture}
\begin{axis}[
xlabel = time,
ylabel = $S$
]

%I'll apply it to a function later
% But as a start, I set the list of points manually
(0,100)
(1,102)
(2,95)
(3,101)
(4,105)
(5,98)
};

\end{axis}
\end{tikzpicture}

% I'll display one consistent type
\begin{tikzpicture}
\pic{BM=orange/100/10/200};	% First point
\end{tikzpicture}
\begin{tikzpicture}
\pic{BM=green/102/10/200};	% Second point
\end{tikzpicture}
\begin{tikzpicture}
\pic{BM=blue/95/10/200}; % Third point
\end{tikzpicture}
\begin{tikzpicture}
\pic{BM=orange/101/10/200};	% Fourth point
\end{tikzpicture}

\end{document}


user 3.14159
This is an answer that literally uses pics as plot marks. The pic has various options which I hope are somewhat selfexplanatory. Please note that generally you will be better off if you dial a rather recent compatibility mode of pgfplots. I chose \pgfplotsset{compat=1.17} and there is no guarantee that the following works with ancient versions. To make a pic a plot mark, one can use something of the sort

\pgfdeclareplotmark{Brownian}{\pic[every mark]{Brownian};}

The every mark key is used to allow the user to pass styles to the pic using the mark options key, so this works just like any other plot mark. The axis direction cs: prefix is crucial to have  reasonable pics inside an axis environment. This also means that you cannot use them outside an axis unless you take extra steps, see the PS below for one out of several options to accomplish this. Finally, we use scatter classes to define different plot marks with different mark options, they can then simply be added in square brackets after the coordinates, as the following example illustrates.

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\tikzset{pics/Brownian/.style={code={
\tikzset{Brownian/.cd,#1}%
\def\pv##1{\pgfkeysvalueof{/tikz/Brownian/##1}}%
\foreach \XXX in {1,...,\pv{N}}
{
\draw[pic actions] (axis direction cs:0,0)
foreach \YYY in {1,...,\pv{M}}
{-- ++ (axis direction cs:{\pv{dx}},{\pv{dy}*(rnd-0.5)})}
;}
}},Brownian/.cd,N/.initial=25,M/.initial=25,dx/.initial=0.04,dy/.initial=0.25}
\begin{document}

\pgfdeclareplotmark{Brownian}{\pic[every mark]{Brownian};}

% Main plot
\begin{tikzpicture}
\begin{axis}[xmax=6,
scatter/classes={
a={mark=Brownian,mark options={red,Brownian/dy=0.4,Brownian/N=40}},
b={mark=Brownian,mark options={blue}},
c={mark=Brownian,mark options={orange,Brownian/dy=0.12}}
},
xlabel = time,
ylabel = $S$
]
scatter src=explicit symbolic,] coordinates {
(0,100) [c]
(1,102) [b]
(2,95) [a]
(3,101) [a]
(4,105) [b]
(5,98) [c]
};
\end{axis}
\end{tikzpicture}
\end{document}

![Screen Shot 2021-02-21 at 10.52.46 AM.png](/image?hash=7aeff7d1ef95bef48985ec906bf564c4cab8eb838254ac75ff932837d1e566e7)

P.S. If one wants to create a pic that works inside *and* outside of an axis environment, one can use the \pgfplotsifinaxis macro. There are other options available, but since this is not central to the current question I won't spell them out since I did not test any of them.

\tikzset{pics/Brownian/.style={code={
\tikzset{Brownian/.cd,#1}%
\def\pv##1{\pgfkeysvalueof{/tikz/Brownian/##1}}%
\foreach \XXX in {1,...,\pv{N}}
{\pgfplotsifinaxis{%
\draw[pic actions] (axis direction cs:0,0)
foreach \YYY in {1,...,\pv{M}}
{-- ++ (axis direction cs:{\pv{dx}},{\pv{dy}*(rnd-0.5)})};}{%
\draw[pic actions] (0,0)
foreach \YYY in {1,...,\pv{M}}
{-- ++ ({\pv{dx}},{\pv{dy}*(rnd-0.5)})};}{%
}}
}},Brownian/.cd,N/.initial=25,M/.initial=25,dx/.initial=0.04,dy/.initial=0.25}



Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.