1

enter image description here

Would you please tell me how to use Latex to draw this picture?

4
  • 3
    See also Example: Neural network on texample.net. Aug 30 '14 at 21:35
  • 2
    Welcome to TeX.SX! On this site, a question should typically revolve around an abstract issue (e.g. "How do I get a double horizontal line in a table?") rather than a concrete application (e.g. "How do I make this table?"). Questions that look like "Please do this complicated thing for me" tend to get closed because they are either "off topic", "too broad", or "unclear". Please try to make your question clear and simple by giving a minimal working example (MWE): you'll stand a greater chance of getting help. Aug 30 '14 at 21:35
  • 3
    It'd be great if you could make your title a bit more descriptive - imagine looking at your question in a few month's time... Would it be a good title? Would it come up in a search result? Have a search for latex trees that grow sideways :)
    – cmhughes
    Aug 30 '14 at 21:38
  • See for example tex.stackexchange.com/questions/182460/…
    – Fran
    Aug 30 '14 at 23:48
9

Here a simple way using pst-node and multido:

\documentclass[1pt, pdf, svgnames]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fourier}
\usepackage{pstricks-add}
\usepackage{xcolor}

\begin{document}

\begin{pspicture}(-1,-4)(4,6)
\psset{radius = 0.15, xunit = 2cm, yunit = 1.2cm, fillstyle = solid}
\psaxes[yaxis = false, linewidth = 0pt,linecolor = white, ticks = none](0,-3.9)(2,-3.9)
\uput[d](-1,-4){Time step}
\Cnode(0,0){O}
\pnodes{A}(1,-2.4)(1,-1.9)(1, -1.4)(1, -0.9)(1,-0.4)(1,0.4)(1, 0.9)(1, 1.4)(1,1.9)(1,2.4)
\pnodes{B}(2,-3.8)(2,-3.3)(2, -2.8)(2, -2.3)(2,-1.8)(2,-1)(2, -0.5)(2, 0)(2,0.5)(2,1)(2,1.8)(2, 2.3)(2, 2.8)(2,3.3)(2,3.8)
\Cnode(O){} \multido{\i = 0 + 1}{10}{\Cnode[fillcolor =LightSteelBlue ](A\i){C\i}}
\multido{\i = 2 + 5}{2}{\Cnode[fillcolor = white](A\i){}}
\multido{\i = 0 + 1}{15}{\Cnode(B\i){D\i}}
\multido{\i = 0 + 1}{10}{\ncline{C\i}{D\i}\fpAdd{\i}{5}{\j}\ncline{C\i}{D\j}}%
\ncline{O}{C2}\ncline{O}{C7}
\psset{linestyle = dashed}
\multido{\i = 0 + 1}{10}{\ncline{O}{C\i}}%
\end{pspicture}

\end{document}

enter image description here

1
  • Beautiful :) I love it Thank you so much Bernard !!!
    – Nguyen
    Aug 31 '14 at 19:22
5

Here's a different approach using Metapost that preserves the right angles in the OP art work.

The link above explains how to get started with Metapost.

enter image description here

prologues := 3;
outputtemplate := "%j%c.eps";

beginfig(1);

% unit width, height, and radius of the nodes 
u = 46; v = 17; r = 4; 
% a W-shaped path to draw 
% with five points: points 0 and 4 are the ends; 1, 2, 3 are corners
path W, w;
W = ((-1,-1) -- (-1,0) -- (0,0) -- (0,1) -- (1,1))
    scaled sqrt(2) scaled u rotated 45;

for i=-2 upto 2:
   % make a copy of the path, shifted across and up
   w := W shifted (2u, i*v); 
   % draw it, and draw connections from the origin
   draw w;
   draw origin -- point 1 of w if i<>0: dashed evenly scaled .8 fi;
   draw origin -- point 3 of w if i<>0: dashed evenly scaled .8 fi;
   % add the nodes on top
   for j = 0 upto 4:
      fill fullcircle scaled 2r shifted point j of w withcolor if ((j=1) or (j=3)) and (i<>0): .6 fi white;
      draw fullcircle scaled 2r shifted point j of w; 
   endfor
endfor

% put the final node at the origin
fill fullcircle scaled 2r withcolor white;
draw fullcircle scaled 2r;

% text labels
label.bot(btex Time step etex, (-u,-8v));
for i=0 upto 2: label.bot(decimal i, (i*u,-8v)); endfor

endfig;
end.

Explanatory notes

I've tried to make the code self-explanatory, but here are some notes.

  • The three parameters at the beginning control the size and shape of the figure. u defines the width between the columns of discs, v the vertical gap between successive discs, and r the radius of each disc.

  • Next I defined a zig-zag path that looks a bit like a sigma or a sideways W once it is scaled and rotated to the right size and position.

  • The for-loop draws a copy of this W-shape five times to produce the desired network. First the W is drawn, then a line is drawn from the origin to the two left-hand corners. Finally the inner loop draws a disc on each point of the W, neatly covering up the joins.

  • Note the use of the "inline" if .. fi construction to vary the patterns and fill colours.

  • Note the use of the assignment operator := to overwrite w in each iteration.

1
  • You may want to include use instructions :) Aug 31 '14 at 22:05

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.