# Drawing a network of lines and discs

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

• See also Example: Neural network on texample.net. Aug 30 '14 at 21:35
• 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
• 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 :) Aug 30 '14 at 21:38
• See for example tex.stackexchange.com/questions/182460/…
– Fran
Aug 30 '14 at 23:48

Here a simple way using pst-node and multido:

\documentclass[1pt, pdf, svgnames]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fourier}
\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}}
\ncline{O}{C2}\ncline{O}{C7}
\psset{linestyle = dashed}
\multido{\i = 0 + 1}{10}{\ncline{O}{C\i}}%
\end{pspicture}

\end{document}


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

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.

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.

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