9

I have found a post about: How to add a jitter to a scatter plot with pgfplots. I'd like to add jitter to a straight green line to recreate this graph.enter image description here.

Would this be the best way do you think? Also are the arrows decorations?

    \documentclass{standalone}
\usepackage{pgfplots}
\usepackage{amsmath}

\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=-4,xmax=+0, ymin=-0.5,ymax=4.5, axis lines=left] 

\addplot[draw=green, mark=none, ultra thick, domain=-4.0:-0.1,
         samples=100] 
    {2}
    node [midway, above right] {\small $\bar{U}$ Time-average velocity}; 

\end{axis} 
\end{tikzpicture}
\end{document}
  • 1
    Perhaps make this in paint? – HCAI Jun 18 '13 at 13:16
  • No, perhaps put a clear image for what you mean for jitter to a straight green line: this might clarify a bit what you're wondering to everybody. :) – Claudio Fiandrino Jun 18 '13 at 13:21
  • Just apply the theory of efficient markets to the green line, and on the basis of no-arbitrage, it should converge with the fair value. – Nicholas Hamilton Jun 18 '13 at 13:30
9

This approach is really similar to vrleboss' suggestion, but in order to fit the arrow for the fluctuating velocity, we'll need to simulate autocorrelated noise (or try lots of realisations of the uncorrelated noise).

Here I've used a product of two cosine functions as the base function, and then added random noise on top:

\documentclass{standalone}
\usepackage{pgfplots}
\usepackage{amsmath}

\begin{document}
\begin{tikzpicture}
\pgfmathsetseed{1}
\begin{axis}[xmin=-4,xmax=+0, ymin=-0.5,ymax=4.5, axis lines=left,
    clip=false] 

\addplot[draw=black, mark=none, ultra thick, domain=-4.0:-0.1,
         samples=2] 
    {2}
    node [right] {\small $\bar{U}$ Time-average velocity}; 
\addplot[draw=red, mark=none, ultra thick, domain=-4.0:-0.1,
         samples=100] 
    {2+0.8*cos(x*300)*cos(x*50)+rand/5}
    node [red, right] {\small $U$ Instantaneous velocity}
    coordinate [pos=0.25] (point); 
\draw [ultra thick, blue, latex-latex] (point) -- (point|-{axis cs:0,2}) node [pos=0, anchor=-160] {$u'$ Fluctuating velocity};
\end{axis} 
\end{tikzpicture}
\end{document}
  • 2
    To have an even nicer curve add the smooth option to \addplot[...] – vrleboss Jun 18 '13 at 14:07
5

I would use the rand function. The decoration produces non-causal curves.

\begin{tikzpicture}
\begin{axis}[xmin=-4,xmax=+0, ymin=-0.5,ymax=4.5, axis lines=left] 

\addplot[draw=green, mark=none, ultra thick, domain=-4.0:-0.1,
         samples=100] 
    {2}
    node [midway, above right] {\small $\bar{U}$ Time-average velocity}; 

\addplot[purple,ultra thick, domain=-4.0:-0.1,samples=50] {0.5*rand+2};
\end{axis} 
\end{tikzpicture}

enter image description here

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.