8

enter image description here

Beyond the solution to this particular diagram, can you explain if there is a general set of steps that you would follow to obtain this code?

My guesses: Would conversion to vector graphics give some guidelines?

Are there parts of the process that can be automated? Etc.

I tried: Using Inkscape to convert to vector graphics and somehow get a bunch of coordinates that I could use as a guideline for the tikz code.

I got the following so far (I took some code from this answer):

\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{decorations.text}

\pgfmathdeclarefunction{gauss}{3}{%
\pgfmathparse{1/(#3*sqrt(2*pi))*exp(-((#1-#2)^2)/(2*#3^2))}%
}

\begin{document}‎‎

\begin{tikzpicture}
\draw[draw=none](0,4)--node[anchor=center, above] (A) {Marginal
distribution of Brownian motion through time} (10,4) ;
\draw[->,very thick](0,0)--(0,4) node[anchor=south, above left,
rotate=90] {Spacial distribution};
\draw[->,very thick](0,0)-- node[anchor=north, below] {Time} (10,0);
\draw[dotted, domain=0:9,samples=35,thick] plot ({\x+0.5},
{sqrt(\x)/2+2});
\draw[dotted, domain=0:9,samples=35, thick, smooth, postaction=
{decorate, decoration={raise=-10pt, text along path,text 
align=center,text={Spread of Willow Tree}}}] plot ({\x+0.5},
{-sqrt(\x)/2+2});
\draw[very thin, domain=-0.5:2.5,samples=35] plot({gauss(\x, 1, 1)+1},
{\x+1}) node (B) {};
\draw[very thin, domain=-0.5:2.5,samples=35] plot({gauss(\x, 1, 0.5)+3},
{\x+1}) node (C) {};
\draw[very thin, domain=-0.5:2.5,samples=35] plot({gauss(\x, 1, 0.25)+5},
{\x+1}) node (D) {};
\draw[very thin, domain=-0.5:2.5,samples=35] plot({gauss(\x, 1, 0.2)+7},
{\x+1}) node (E) {};
\draw[->] (A) to (B);
\draw[->] (A) to (C);
\draw[->] (A) to (D);
\draw[->] (A) to (E);
\end{tikzpicture}

\end{document}

which produces:

enter image description here

  • 3
    What have you tried? What are you stuck on? You are basically asking for answers which not only draw your figure from scratch but also provide something like part of the pgfplots manual and cover image conversion, automation and unspecified further issues. Apart from anything else, that is much too broad. It cannot possibly be answered reasonably in this format. Also, what are you converting to vector and how? And why would that produce code? We don't know anything about the starting point so automation is essentially out of the question. – cfr Jul 29 '15 at 15:58
  • @cfr See the edit. Those questions were only my guesses. If they don't exist the answer doesn't need to add them. – Anna Taurogenireva Jul 29 '15 at 16:11
  • Well, yes. You can use Inkscape to export TikZ code. That is an option. It is not very easy to edit the results as it won't be especially readable, but if you just need the code, it should work. Obviously, that will just draw it. It won't make it a plot, for example. – cfr Jul 29 '15 at 18:07
  • Thanks for posting some code. Could you please make it into a proper MWE? – cfr Jul 29 '15 at 18:08
  • 1
    @cfr No idea what is MWE. Market Energy Partners? – Anna Taurogenireva Jul 29 '15 at 18:12
  • @MlazhinkaShungGronzalezLeWy a MWE is a minimal working example; basically, a complete and minimal document showing either the problem or, as in your case, the current state of things. I completed your snippet into a proper MWE and added the resulting image. I hope it's OK. – Gonzalo Medina Jul 29 '15 at 19:41
  • Why is this question downvoted twice? What else do you need ? – percusse Jul 29 '15 at 19:44
  • @percusse I guess down-voters were too hasty and voted before the code was added. Down-voting so soon, specially when OP reacts, has always seemed to be a disgrace to me. At least my up-vote could neutralize one of the down-votes, and someone else's too. – Gonzalo Medina Jul 29 '15 at 19:46
  • @GonzaloMedina There was already code and it was only missing the preamble before the downvotes. I guess MWE stands for My way of example for them. The other vote is mine :) – percusse Jul 29 '15 at 19:48
  • 2
    @GonzaloMedina There was no code when the original question was posted and none was added in the first edit. Plus the OP is not new to the site and so I think that makes a difference to what it is reasonable to expect. One of the down-votes was mine although I would not have added a second one. And I would almost certainly not have down-voted if the user was new to the site. But I also try to watch questions in this case so that I can react to changes. I think calling it a disgrace is a bit strong in this kind of case, myself, even if you disagree. – cfr Jul 29 '15 at 20:42
  • Could you clarify whether the code you've now got produces the image you want? If not, what do you want to look different? Right now, it seems that you have an answer to part of your question in the question because you've basically adapted the code to your needs already. Apologies for not explaining MWE. I had assumed, given that you'd obviously been asking/answering questions here for a while, that you would know what I meant. However, it seems nobody bothered to mention it before. This is unfortunate, because it makes it much easier to ask questions, solve problems, and get answers! – cfr Jul 29 '15 at 20:52
  • I also think that the method you used is a good one: find an example which does something somewhat like you want and try to adapt it to do just what you want. One thing this often does as well, is give you a command or keyword which you can search for in the documentation. With TikZ/PGF, this can really help in finding relevant bits of the rather bloated manuals. – cfr Jul 29 '15 at 20:57
  • @cfr Sorry if it sounded too harsh. However, I thought the code snippet was there, just missing the preamble, when the down-votes were cast, so that's what I called it a disgrace. – Gonzalo Medina Jul 29 '15 at 22:04
  • @GonzaloMedina I don't know about the second one. But I down-voted when I first commented and there was no code at all. (Hence my 'what have you tried?' opening.) As I say, if it was a new user, I would not have down-voted at that point though I might well have commented. At the time, the question seemed to be a 'draw-this-for-me and explain-everything-you-do and explain-all-the-options' which I did not think a reasonable starting point coming from somebody familiar with the site. – cfr Jul 29 '15 at 22:19

2 Answers2

7

Should point you in the right direction...

\documentclass[tikz, border=5]{standalone}
\begin{document}
\begin{tikzpicture}[>=stealth, line cap=round]
\draw [thick, ->] (0,-2) -- (0, 2)
  node [midway, sloped, above] {Spatial distribution};
\draw [thick, ->] (0,-2) -- (10,-2)
  node [midway, below] {Time};
\draw [thick, dotted] 
  plot [domain=-1.5:1.5, samples=50] ({(\x*2)^2+.5},\x)
  node [right, align=center] {Spread of \\ willow tree};
\foreach \t [count=\i] in {.1,0.5,1,1.5}
  \draw plot [domain=-3:3, samples=20, smooth]
    ({\i*2 + sqrt(0.5*\t*pi)*exp(-0.5*\t*pow(\x,2))}, \x/2)
    coordinate (distribution-\i);
\node [above] (label) at (5,2) 
  {Marginal distribution of Brownian motion through time};
\foreach \i in {1,...,4}
  \draw [->, shorten >=1ex] (label) -- (distribution-\i);
\end{tikzpicture}
\end{document}

enter image description here

Mark Wibrow
  • 70,437
6

Here is a pgfplots approach:

pgfplots

\documentclass[tikz,border=10pt]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{decorations.text}

\pgfmathdeclarefunction{gauss}{3}{%
\pgfmathparse{1/(#3*sqrt(2*pi))*exp(-((#1-#2)^2)/(2*#3^2))}%
}

\begin{document}

\begin{tikzpicture}
  \begin{scope}[rotate=-90]

  \begin{axis}[
    domain=-0.5:2.5,
    xmin=-1, xmax=3,
    ymin=0, ymax=10,
    xlabel=Spacial distribution, ylabel=Time,
    xtick=\empty, ytick=\empty,
    axis x line=bottom, axis y line=right,
    x axis line style = {very thick,stealth-},
    y axis line style = {very thick},
    height=\textwidth,
    width=.5\textwidth,
    clip=false]

    \addplot[mark=none, thick, dotted,
      postaction={decorate, decoration={raise=-10pt, text along path,
        text align={right, right indent=3.5cm},text={|\scriptsize|Spread of Willow Tree}}}]
      {((x-1)*2)^2+.5};

    \node [xshift=-1cm,rotate=90] (label) at (current bounding box.west) 
      {Marginal distribution of Brownian motion through time};

    \foreach \t/\i in {1/1, 0.5/3, 0.25/5, 0.2/7} {
      \addplot[samples=35,smooth] {gauss(x, 1, \t)+\i};          
      \edef\temp{
        \noexpand\coordinate (g-\i) at (axis cs:-0.5,\i);
        \noexpand\draw [->, shorten >=2ex] (label) -- (g-\i);}
      \temp
    }
  \end{axis}
  \end{scope}

\end{tikzpicture}

\end{document}
sergej
  • 6,461
  • 32
  • 62