tikz

resources

examples

tikz is used to draw graphics in latex documents
it can be imported like this:

  \usepackage{tikz}

primitive shapes

drawing primitive shapes like lines/rectangles is very simple

lines

  \tikz\draw (0,0) -- (3,2);

broken link: file:/home/mahmooz/brain/out/tJcTbR.svg

here |- generates a broken line while -- generates a straight line
  \tikz\draw (0,0) -- (3,2) -- (5,0) |- (4,3);
\tikz\draw[->] (-2,0) -- (-3,0);

broken link: file:~/brain/out/E8OU1y.svg

polygons

tikz has lots of builtin shapes like:

  \tikz\draw (0,0) circle (10px);
\tikz\draw[fill=gray!30!white] (0,0) ellipse (28pt and 20pt);
\tikz\draw[line width=2mm] (0,0) arc (30:200:1cm);
\tikz\fill[color=red] (0,0) rectangle (2,1);

broken link: file:~/brain/out/4GY1Ec.svg

and if tikz doesnt have a specific shape we can always use lines to draw it
  % use cycle instead of manually writing (0,0)
\tikz\draw (0,0) -- (4,0) -- (4,4) -- cycle;

broken link: file:~/brain/out/5kARLC.svg

nodes

nodes are used to represent entities for various purposes including inserting text and connecting entities

  \begin{tikzpicture} \draw
(1,1) node[circle, draw]{A} --
(2,2) node[circle, draw]{B};
\end{tikzpicture}

broken link: file:~/brain/out/JuXxvo.svg

to get a more "proper" result we use the anchor argument
  \begin{tikzpicture} \draw
(1,1) node[anchor=north east, circle, draw]{A} --
(2,2) node[anchor=south west, circle, draw]{B};
\end{tikzpicture}

broken link: file:~/brain/out/fwDlQd.svg

  \begin{tikzpicture} \draw
(0,0) node[anchor=north, rectangle, draw, label=above:Top, label=below:Bottom]{inside rectangle} |-
(3,3) node[anchor=west, rectangle, draw, label=above:Top, label=below:Bottom]{another rectangle};
\end{tikzpicture}

broken link: file:~/brain/out/vERNnP.svg

  \begin{tikzpicture}
% draw the sets
\filldraw[fill=blue!20, draw=blue!60] (-1.5,0) circle (1cm);
\filldraw[fill=red!20, draw=red!60] (1.5,0) circle (1cm);
% the texts
\node at (-1.5,1.5) {$X$};
\node at (1.5,1.5) {$Y$};
% the points in the sets (here I just create nodes to use them later on to position
% the circles and the arrows
\node (x1) at (-1.5,0.7) {$a$};
\node (x2) at (-1.5,0.3) {$b$};
\node (x3) at (-1.5,-0.2) {$c$};
\node (x4) at (-1.5,-0.7) {$d$};
\node (y1) at (1.5,0.7) {$1$};
\node (y2) at (1.5,0.3) {$2$};
\node (y3) at (1.5,-0.2) {$3$};
\node (y4) at (1.5,-0.7) {$4$};
% draw the arrows
\draw[->] (x1) -- (y4);
\draw[->] (x2) -- (y2);
\draw[->] (x3) -- (y1);
\draw[->] (x4) -- (y3);
\end{tikzpicture}

broken link: file:~/brain/out/BgY0KZ.svg

  \begin{tikzpicture}[
> = stealth, % arrow head style
shorten > = 1pt, % don't touch arrow head to node
auto,
node distance = 1cm, % distance between nodes
semithick % line style
]
\tikzstyle{every state}=[
draw = black,
thin,
fill = cyan!29,
minimum size = 5mm
]
\node[state] (a) {$a$};
\node[state] (b)[below left=of a] {$b$};
\node[state] (c)[below left=0.3cm and 0.3cm of b] {$c$};
\node[state] (f)[below left=0.3cm and 0.3cm of c] {$f$};
\node[state] (j)[below left=0.3cm and 0.3cm of f ] {$j$};
\node[state] (d)[below left=0.3cm and 0.3cm of j] {$d$};
\node[state] (i)[below left=0.3cm and 0.3cm of d] {$i$};
\path[->] (a) edge node {} (b);
\path[->] (b) edge node {} (c);
\path[->] (c) edge node {} (f);
\path[->] (f) edge node {} (j);
\path[->] (j) edge node {} (d);
\path[->] (d) edge node {} (i);
\path[->] (b) edge[bend right=45, blue, very thick] node {} (j);
\end{tikzpicture}

#+RESULTS[caaaddd560a40614c2c9b49b28afea7d639ccd6d]:
broken link: file:~/brain/out/sP1ObG.svg

2d plots

you can play around with the parameters to see how they affect the drawing

  \begin{tikzpicture}
\draw[->] (-3, 0) -- (4.2, 0) node[right] {$x$};
\draw[->] (0, -3) -- (0, 4.2) node[above] {$y$};
\draw[scale=0.5, domain=-3:3, smooth, variable=\x, blue] plot ({\x}, {\x*\x});
\draw[scale=0.5, domain=-3:3, smooth, variable=\y, red] plot ({\y*\y}, {\y});
\end{tikzpicture}

broken link: file:/home/mahmooz/brain/out/cdn8lr.svg

  \begin{tikzpicture}
% drawing the grid
\draw[thick, color = gray, step = 1cm, dashed] (-1,-1) grid (5,5);
\draw[->] (-2,0) -- (6,0) node[right]{$x$};
\draw[->] (0,-2) -- (0,6) node[above]{$y$};
% defining nodes
\node (A) at (1,2);
\node (B) at (2,4);
\node (C) at (0,4);
\node (D) at (5,2);
\node (E) at (1.65, 3.35);
% draw the lines
\draw[red, thick, dashed] (A) -- (B);
\draw[black, thick] (C) -- (D);
% draw the points
\draw[fill=orange] (E) circle (2pt) node[right] {E(1.65, 3.35)};
\draw[fill=blue] (A) circle (2pt) node[below right] {A(1,2)};
\draw[fill=blue] (B) circle (2pt) node[above left] {B(2,4)};
\draw[fill=blue] (C) circle (2pt) node[below left] {C(0,4)};
\draw[fill=blue] (D) circle (2pt) node[above right] {D(5,2)};
\end{tikzpicture}

broken link: file:/home/mahmooz/brain/out/9DtrIs.svg

pgfplots

you can use the pgfplots package which is written using tikz to make things easier, include it using:

  \usepackage{pgfplots}
example usage:
  \begin{tikzpicture}
\begin{axis}[domain=-4:4, samples=100, grid=major,
restrict y to domain=0:4, xlabel=$x$, ylabel=$y(x)$, legend pos=north west]
\addplot [color=red] {2*exp(x)};
\addplot [color=green] {exp(x)};
\addplot [color=purple] {exp(-x)};
\addplot [color=blue] {2*exp(-x)};
\legend{$2e^x$, $e^x$, $e^{-x}$, $2e^{-x}$}
\end{axis}
\end{tikzpicture}

broken link: file:~/brain/out/gSMHG5.svg

  \usepgfplotslibrary{fillbetween}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle, xlabel=$x$, ylabel=$y$,
xmin=-3, xmax=3,
ymin=-10, ymax=10,
xtick distance=1, ytick distance=4]
\addplot [domain=-2.5:2.5, samples=100, name path=f, thick, color=red!50]
{3*x^3 - x^2 - 10*x};
\addplot [domain=-2.5:2.5, samples=100, name path=g, thick, color=blue!50]
{- x^2 + 2*x};
\addplot[red!10, opacity=0.4] fill between[of=f and g, soft clip={domain=-2:2}];
\node[color=red, font=\footnotesize] at (axis cs: -1.6,7) {$f(x)=3x^3 - x^2 - 10x$};
\node[color=blue, font=\footnotesize] at (axis cs: 1.1,2.2) {$g(x)=- x^2 + 2x$};
\end{axis}
\end{tikzpicture}

broken link: file:~/brain/out/7c8Bc5.svg
scatter plot:

3d plots

for 3d plots we use the package tikz-3dplot

  \usepackage{tikz-3dplot}
we start with a simple 3d plot with 3 vectors
  \tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords, scale=2]
% draw main axes
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
% draw the vector lines
\draw[thick,color=blue,->] (0,0,0) -- (.7,.8,0) node[anchor=north]{$\vec{v_1}$};
\draw[thick,color=blue,->] (0,0,0) -- (0,.7,.3) node[anchor=west]{$\vec{v_2}$};
\draw[thick,color=blue,->] (0,0,0) -- (0,.2,.7) node[anchor=south]{$\vec{v_3}$};
\end{tikzpicture}

broken link: file:/home/mahmooz/brain/out/EcA741.svg

  \tdplotsetmaincoords{70}{130} % set initial 3d rotation
\begin{tikzpicture}[tdplot_main_coords, scale = 1]
% draw the main axes
\draw[thick, ->] (-2,0,0) -- (5,0,0) node[below left] {$x$};
\draw[thick, ->] (0,-2,0) -- (0,5,0) node[below right] {$y$};
\draw[thick, ->] (0,0,-2) -- (0,0,5) node[left] {$z$};
\draw[thick, blue, dashed] (-1,4,8) -- (-5,-4,-4);
\draw[thick, red, <->] (-4,-2,-1) -- (-2,2,5) node[midway, above, sloped, black] {vector};
\filldraw[draw=black, fill=blue, opacity=0.3] (0,6,7) -- (-3,1,5) -- (-2,1,4) -- cycle;
\draw[fill=black] (0,6,7) circle (2pt) node[below right] {(0,6,7)};
\draw[fill=black] (-3,1,5) circle (2pt) node[above left] {(-3,1,5)};
\draw[fill=black] (-2,1,4) circle (2pt) node[below left] {(-2,1,4)};
\end{tikzpicture}

broken link: file:/home/mahmooz/brain/out/jAMOqE.svg

  % set the plot display orientation
% syntax: \tdplotsetdisplay{\theta_d}{\phi_d}
\tdplotsetmaincoords{60}{110}
% define polar coordinates for some vector
% TODO: look into using 3d spherical coordinate system
\pgfmathsetmacro{\rvec}{.8}
\pgfmathsetmacro{\thetavec}{30}
\pgfmathsetmacro{\phivec}{60}
% use the tdplot_main_coords style to implement the display the coordinate transformation provided by 3dplot
\begin{tikzpicture}[scale=5,tdplot_main_coords]
% set up some coordinates
% -----------------------
\node (O) at (0,0,0);
% determine a coordinate (P) using (r,\theta,\phi) coordinates. This command
% also determines (Pxy), (Pxz), and (Pyz): the xy-, xz-, and yz-projections
% of the point (P).
% syntax: \tdplotsetcoord{Coordinate name without parentheses}{r}{\theta}{\phi}
\tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec}
% draw the main coordinate system axes
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
% draw a vector from origin to point (P)
\draw[-stealth,color=red] (O) -- (P);
% draw projection on xy plane, and a connecting line
\draw[dashed, color=red] (O) -- (Pxy);
\draw[dashed, color=red] (P) -- (Pxy);
% draw the angle \phi, and label it
% syntax: \tdplotdrawarc[coordinate frame, draw options]{center point}{r}{angle}{label options}{label}
\tdplotdrawarc{(O)}{0.2}{0}{\phivec}{anchor=north}{$\phi$}
% set the rotated coordinate system so the x'-y' plane lies within the
% "theta plane" of the main coordinate system
% syntax: \tdplotsetthetaplanecoords{\phi}
\tdplotsetthetaplanecoords{\phivec}
% draw theta arc and label, using rotated coordinate system
\tdplotdrawarc[tdplot_rotated_coords]{(0,0,0)}{0.5}{0}{\thetavec}{anchor=south west}{$\theta$}
% draw some dashed arcs, demonstrating direct arc drawing
\draw[dashed,tdplot_rotated_coords] (\rvec,0,0) arc (0:90:\rvec);
\draw[dashed] (\rvec,0,0) arc (0:90:\rvec);
% set the rotated coordinate definition within display using a translation
% coordinate and Euler angles in the "z(\alpha)y(\beta)z(\gamma)" euler rotation convention
% syntax: \tdplotsetrotatedcoords{\alpha}{\beta}{\gamma}
\tdplotsetrotatedcoords{\phivec}{\thetavec}{0}
% translate the rotated coordinate system
% syntax: \tdplotsetrotatedcoordsorigin{point}
\tdplotsetrotatedcoordsorigin{(P)}
% use the tdplot_rotated_coords style to work in the rotated, translated coordinate frame
\draw[thick,tdplot_rotated_coords,->] (0,0,0) -- (.5,0,0) node[anchor=north west]{$x'$};
\draw[thick,tdplot_rotated_coords,->] (0,0,0) -- (0,.5,0) node[anchor=west]{$y'$};
\draw[thick,tdplot_rotated_coords,->] (0,0,0) -- (0,0,.5) node[anchor=south]{$z'$};
% WARNING: coordinates defined by the \coordinate command (eg. (O), (P), etc.)
% cannot be used in rotated coordinate frames. Use only literal coordinates.
% draw some vector, and its projection, in the rotated coordinate frame
\draw[-stealth,color=blue,tdplot_rotated_coords] (0,0,0) -- (.2,.2,.2);
\draw[dashed,color=blue,tdplot_rotated_coords] (0,0,0) -- (.2,.2,0);
\draw[dashed,color=blue,tdplot_rotated_coords] (.2,.2,0) -- (.2,.2,.2);
% show its phi arc and label
\tdplotdrawarc[tdplot_rotated_coords,color=blue]{(0,0,0)}{0.2}{0}{45}{anchor=north west,color=black}{$\phi'$}
% change the rotated coordinate frame so that it lies in its theta plane.
% Note that this overwrites the original rotated coordinate frame
% syntax: \tdplotsetrotatedthetaplanecoords{\phi'}
\tdplotsetrotatedthetaplanecoords{45}
% draw theta arc and label
\tdplotdrawarc[tdplot_rotated_coords,color=blue]{(0,0,0)}{0.2}{0}{55}{anchor=south west,color=black}{$\theta'$}
\end{tikzpicture}

broken link: file:/home/mahmooz/brain/out/EUmDsX.svg

  \begin{tikzpicture}[scale=3,line cap=round]
\begin{scope}[rotate around y=45,rotate around z=30,canvas is zx plane at y=0]
\draw [green!50!black, dashed, ultra thick] (-1,0) arc (180:360:1);
\end{scope}
\begin{scope}[canvas is zx plane at y=0]
\draw [ultra thin, step = 0.25, lightgray] (-1,-1) grid (1,1);
\draw [dashed, red] (225:1) -- (0,0) -- (135:1);
\draw [green, ultra thick] (0, 0) circle (1);
\foreach\i in{0,90}
{
\filldraw [fill= orange!20, draw = orange] (0,0) -- (\i:0.5) arc (\i:\i+45:0.5) -- cycle;
\draw [->, orange, ultra thick] (0,0) -- (\i:1);
}
\node [anchor = north west] at (0, 1) {$\vec{i}$};
\node [anchor = north] at (1, 0) {$\vec{j}$};
\end{scope}
\begin{scope}[rotate around y=45,rotate around z=30]
\draw [canvas is zx plane at y=0, green!50!black, ultra thick] (1, 0) arc (0:180:1);
\foreach\i in {0,90}
\filldraw [canvas is xy plane at z=0, fill=red!20, draw=red] (0,0) -- (\i-30:0.4) arc (\i-30:\i:0.4) -- cycle;
\draw [->, red, ultra thick] (0,0,0) -- (1,0,0);
\draw [->, red, ultra thick] (0,0,0) -- (0,1,0);
\draw [->, red, ultra thick] (0,0,0) -- (0,0,1);
\end{scope}
\draw [->, orange, ultra thick] (0,0,0) -- (0,1,0) node[black, anchor=south east] at (0, 1, 0) {$\vec{z_0}$};
\draw [canvas is zx plane at y=0.75, ->, blue] (0,-0.15) arc (-90:180:0.15);
\node at (0.3,0.9) {$\dot{\Psi}\vec{z_0}$};
\end{tikzpicture}

broken link: file:/home/mahmooz/brain/out/ggUg1y.svg

  \tdplotsetmaincoords{80}{45}
\tdplotsetrotatedcoords{-90}{180}{-90}
%% style for surfaces
\tikzset{surface/.style={draw=blue!70!black, fill=blue!40!white, fill opacity=.6}}
%% macros to draw back and front of cones
%% optional first argument is styling; others are z, radius, side offset (in degrees)
\newcommand{\coneback}[4][]{
%% start at the correct point on the circle, draw the arc, then draw to the origin of the diagram, then close the path
\draw[canvas is xy plane at z=#2, #1] (45-#4:#3) arc (45-#4:225+#4:#3) -- (O) --cycle;
}
\newcommand{\conefront}[4][]{
\draw[canvas is xy plane at z=#2, #1] (45-#4:#3) arc (45-#4:-135+#4:#3) -- (O) --cycle;
}
\begin{tikzpicture}[tdplot_main_coords]
\coordinate (O) at (0,0,0);
%% make sure to draw everything from back to front
\coneback[surface]{-1.5}{2.5}{-15}
\coneback[surface]{-3}{2}{-10}
\draw (0,0,-5) -- (O);
\conefront[surface]{-3}{2}{-10}
\conefront[surface]{-1.5}{2.5}{-15}
\filldraw[surface] circle (3);
\draw[->] (-6,0,0) -- (6,0,0) node[right] {$x$};
\draw[->] (0,-6,0) -- (0,6,0) node[right] {$y$};
\coneback[surface]{1.5}{2.5}{15}
\coneback[surface]{3}{2}{10}
\draw[->] (O) -- (0,0,5) node[above] {$z$};
\conefront[surface]{3}{2}{10}
\conefront[surface]{1.5}{2.5}{15}
\end{tikzpicture}

broken link: file:/home/mahmooz/brain/out/o79smS.svg

  \newcommand{\ve}[1]{\ensuremath{\mathbf{#1}}}
\newcommand{\ud}[0]{\mathrm{d}}
\tikzset{
vector/.style = {
thick,
> = stealth',
},
axis/.style = {
very thin,
> = stealth',
},
}
\tdplotsetmaincoords{70}{120}
\tdplotsetrotatedcoords{90}{90}{90}
\begin{tikzpicture}[tdplot_main_coords,scale=0.5]
\draw (0,0,0) -- ++(0,-2.3,0) node[left]{$-$};
% draw a condensor plate
\draw[fill=lightgray] (-1.5,0,-1.5)--(-1.5,0,1.5)--(1.5,0,1.5)--(1.5,0,-1.5)--cycle;
\draw[fill=lightgray] (1.5,0,-1.5)--(1.5,-0.2,-1.5)--(1.5,-0.2,1.5)--(1.5,0,1.5)--cycle;
\draw[fill=lightgray] (1.5,-0.2,1.5)--(-1.5,-0.2,1.5)--(-1.5,0,1.5)--(1.5,0,1.5)--cycle;
\def\q{-2.3}
% draw surface
\draw (0,-0.5*\q,0) coordinate(R);
\tdplotdrawarc[tdplot_rotated_coords,fill opacity=0.5,fill=lightgray!30,draw=black]{(R)}{3}{0}{360}{}{}
\draw[tdplot_rotated_coords](R)++(-110:3) node[below left]{$S_2$};
\draw[tdplot_rotated_coords](R)++(70:3) node[above]{$C$};
% draw second condensor plate
\draw[fill=lightgray] (-1.5,0-\q,-1.5)--(-1.5,0-\q,1.5)--(1.5,0-\q,1.5)--(1.5,0-\q,-1.5)--cycle;
\draw[fill=lightgray] (1.5,0-\q,-1.5)--(1.5,-0.2-\q,-1.5)--(1.5,-0.2-\q,1.5)--(1.5,0-\q,1.5)--cycle;
\draw[fill=lightgray] (1.5,-0.2-\q,1.5)--(-1.5,-0.2-\q,1.5)--(-1.5,0-\q,1.5)--(1.5,0-\q,1.5)--cycle;
\draw (0,-\q,0)--++(0,2,0)node[right]{$+$};
\end{tikzpicture}%
\begin{tikzpicture}[tdplot_main_coords,scale=0.5]
\tdplotsetrotatedcoords{90}{90}{90}%
\draw (0,0,0)--++(0,-2.3,0)node[left]{$-$};
% draw condensore plate
\draw[fill=lightgray] (-1.5,0,-1.5)--(-1.5,0,1.5)--(1.5,0,1.5)--(1.5,0,-1.5)--cycle;
\draw[fill=lightgray] (1.5,0,-1.5)--(1.5,-0.2,-1.5)--(1.5,-0.2,1.5)--(1.5,0,1.5)--cycle;
\draw[fill=lightgray] (1.5,-0.2,1.5)--(-1.5,-0.2,1.5)--(-1.5,0,1.5)--(1.5,0,1.5)--cycle;
% draw surface
\def\q{-2.3}
\def\R{3}
\draw (0,-0.5*\q,0) coordinate(R);
\tdplotdrawarc[tdplot_rotated_coords,fill=lightgray,fill opacity=0.5,draw=black]{(R)}{\R}{0}{360}{}{}
\draw[tdplot_rotated_coords](R)++(-110:\R) node[below left]{$S_1$};
\draw[tdplot_rotated_coords](R)++(70:\R) node[above]{$C$};
\tdplotsetrotatedcoords{0}{70}{90}
\draw[tdplot_rotated_coords](R)++(90:\R) coordinate (A) circle(0.5pt);
\draw[tdplot_rotated_coords,fill opacity=0.5,fill=lightgray!30](A)arc(90:270:\R);
\tdplotsetrotatedcoords{90}{90}{90}
\tdplotdrawarc[tdplot_rotated_coords,fill=lightgray!10,draw=black]{(R)}{\R}{0}{360}{}{}
\begin{scope}
% draw condensor plate again, inside (clip outside)
\clip[tdplot_rotated_coords] (R)++(0:\R) arc (0:360:\R);
\draw[fill=lightgray] (-1.5,0,-1.5)--(-1.5,0,1.5)--(1.5,0,1.5)--(1.5,0,-1.5)--cycle;
\draw[fill=lightgray] (1.5,0,-1.5)--(1.5,-0.2,-1.5)--(1.5,-0.2,1.5)--(1.5,0,1.5)--cycle;
\draw[fill=lightgray] (1.5,-0.2,1.5)--(-1.5,-0.2,1.5)--(-1.5,0,1.5)--(1.5,0,1.5)--cycle;
\end{scope}
\draw[tdplot_rotated_coords] (R)++(0:\R) arc (0:360:\R);
% draw second condensor plate
\draw[fill=lightgray] (-1.5,0-\q,-1.5)--(-1.5,0-\q,1.5)--(1.5,0-\q,1.5)--(1.5,0-\q,-1.5)--cycle;
\draw[fill=lightgray] (1.5,0-\q,-1.5)--(1.5,-0.2-\q,-1.5)--(1.5,-0.2-\q,1.5)--(1.5,0-\q,1.5)--cycle;
\draw[fill=lightgray] (1.5,-0.2-\q,1.5)--(-1.5,-0.2-\q,1.5)--(-1.5,0-\q,1.5)--(1.5,0-\q,1.5)--cycle;
\draw (0,-\q,0)--++(0,2,0)node[right]{$+$};
\end{tikzpicture}

broken link: file:/home/mahmooz/brain/out/mq5YoS.svg

3d plots with pgfplots

the \addplot3 makes drawing 3d graphics much easier, the syntax is simply \addplot {<math expresion of f(x,y)>}; which is a shorthand-hand equivalent for \addplot[<options>] expression {<math expression of f(x,y)>};
consider this example which plots $f(x,y) = x^2 - y^2$:

  \begin{tikzpicture}
\begin{axis}[colorbar]
\addplot3 [
surf,
samples=15,
domain=0:1,y domain=-1:1
] {x^2 - y^2};
\end{axis}
\end{tikzpicture}

broken link: file:~/brain/out/4MXkkm.svg

the colorbar argument passed to the axis environment simply generates the color bar on the right
the surf argument passed to axis environment simply tells it to fill the gaps between the lines to form a solid surface
a very useful variant of \addplot3 is one that takes 3 math expressions, one for each variable, the syntax is:
  \addplot3[<options>] expression {<x expression>, <y expression>, <z expression>};

which for most purposes can be simplified to
  \addplot3{<x expression>, <y expression>, <z expression>};

note that \addplot3(x,y,x^2) is equivalent to \addplot{x^2}
consider the following examples
  \begin{tikzpicture}
\begin{axis}[
axis lines=center,
axis on top,
domain=0:1,
y domain=0:2*pi,
xmin=-1.5, xmax=1.5,
ymin=-1.5, ymax=1.5, zmin=0.0]
\addplot3 [surf, colormap/blackwhite, shader=flat] ({x*cos(deg(y))},{x*sin(deg(y))},{x});
\end{axis}
\end{tikzpicture}

broken link: file:~/brain/out/8mXtxD.svg

    \begin{tikzpicture}
\begin{axis}[view={60}{30}]
\addplot3[surf,shader=flat,
samples=20,
color=red, opacity=0.15,
domain=-1.11:1.11, y domain=0:2*pi,
z buffer=sort
]
({(pi-x)*cos(deg(y))+pi}, {cos(deg(x))}, {(pi-x)*sin(deg(y))});
\addplot3[surf,shader=flat,
samples=20,
color=blue, opacity=0.15,
domain=-1.11:1.11, y domain=0:2*pi,
z buffer=sort]
({(pi-x)*cos(deg(y))+pi}, {x*x-0.25*pi}, {(pi-x)*sin(deg(y))});
\end{axis}
\end{tikzpicture}

broken link: file:~/brain/out/O4rtO3.svg

    \begin{tikzpicture}
\begin{axis}
[ view={45}{20},
unit vector ratio=1 1 1,
xmin=-2, xmax=8,
ymin=-3, ymax=2,
zmin=-5, zmax=5,
width=15cm,
]
\addplot3[surf,shader=flat,
samples=20,
color=red, opacity=0.15,
domain=-1.11:1.11, y domain=0:2*pi,
z buffer=sort,
]
({(pi-x)*cos(deg(y))+pi}, {cos(deg(x))}, {(pi-x)*sin(deg(y))});
\addplot3[surf,shader=flat,
samples=20,
color=red, opacity=0.15,
domain=-1.11:1.11, y domain=0:2*pi,
z buffer=sort]
({(pi-x)*cos(deg(y))+pi}, {x*x-0.25*pi}, {(pi-x)*sin(deg(y))});
\end{axis}
\end{tikzpicture}

broken link: file:~/brain/out/cVNpiY.svg

  \begin{tikzpicture}
\pgfmathsetmacro{\u}{1.5}
\begin{axis}[set layers,
x={(3.2*\u cm,0.0cm)},
y={(0cm,\u cm)},
z={(-\u*0.3535cm,-\u*0.3535cm)},
axis lines=center,
xmin=0
]
\addplot3[opacity=0.2,surf,shader=flat,on layer=axis background,
samples=20,
domain=0:1,y domain=pi:2*pi,
z buffer=sort]
(x,{(x + 1)*cos(deg(y))}, {(x+1) * sin(deg(y))});
\addplot3[opacity=0.4,surf,shader=flat,on layer=main,
samples=40,
domain=0:1,y domain=0:2*pi,
z buffer=sort]
(x,{(x^3 + 1)*cos(deg(y))}, {(x^3 + 1) * sin(deg(y))});
\addplot3[opacity=0.2,surf,shader=flat,on layer=axis foreground,
samples=20,
domain=0:1,y domain=0:pi,
z buffer=sort]
(x,{(x + 1)*cos(deg(y))}, {(x+1) * sin(deg(y))});
\end{axis}
\end{tikzpicture}

broken link: file:~/brain/out/7XtVM6.svg

forest

forest is a package used to draw "binary tree"-like diagrams
it can be imported as:

  \usepackage{forest}

usage

  \begin{forest}
[10
[50
[20]
[30]
]
]
\end{forest}

broken link: file:~/brain/out/mQF4R6.svg

what you put in the brackets is basically a tikz node and can take any shape, for example this is a binary tree with some basic math expressions and various shapes
  \begin{forest}
[$n$,rectangle,draw
[$\dfrac{n}{3}$,circle,draw
[$T\left(\dfrac{n}{9}\right)$,rectangle,draw]
[$T\left(\dfrac{2n}{9}\right)$,circle,draw]
[hello,circle,draw]
]
[$\dfrac{2n}{3}$,circle,draw
[$T\left(\dfrac{2n}{9}\right)$,ellipse,draw]
[$T\left(\dfrac{4n}{9}\right)$,draw]
]
]
\end{forest}

broken link: file:~/brain/out/LOBRBL.svg

to insert a node without drawing it so that you get the effect of an empty child but still have correct indentation for other children we use [,phantom] which is a node that gets inserted but not drawn, example:
  \begin{forest}
[$n$,rectangle,draw
[$\dfrac{n}{3}$,circle,draw
[,phantom]
[$T\left(\dfrac{n}{9}\right)$,circle,draw]
]
[$\dfrac{2n}{3}$,circle,draw
[$T\left(\dfrac{2n}{9}\right)$,circle,draw]
[$T\left(\dfrac{4n}{9}\right)$,circle,draw]
]
]
\end{forest}

broken link: file:~/brain/out/YQJ95R.svg

you can treat the forest environment like tikzpicture, you can freely add more nodes and drawings, to use a node of forest as a tikz node you pass name=<name> to it, example:
  \begin{forest}
[5,circle,draw,name=root
[3,circle,draw
[2,circle,draw
[1,circle,draw]
[,phantom]
]
[,phantom]
]
[10,circle,draw
[7,circle,draw]
[18,circle,draw]
]
]
\node (root_text) at (2,0) {root};
\draw[->, blue] (root) -- (root_text);
\end{forest}

broken link: file:~/brain/out/bupAbG.svg

a more advanced example:
  \begin{forest}
[5,circle,draw,name=root
[3,circle,draw,name=n4
[2,circle,draw,name=n5
[1,circle,draw,name=n6]
[,phantom]
]
[,phantom]
]
[10,circle,draw,name=n1
[7,circle,draw,name=n2]
[18,circle,draw,name=n3]
]
]
% root text
\node (root_text) at (2,0.5) {root};
\draw[->, blue] (root) -- (root_text);
% Tright
\node (Tright_text) at (3,-3) {$T_{\text{right}(\text{root})}$};
\node[draw=red, double, fit=(n1) (n3) (n2), inner sep=1ex, circle] (Tright) {};
\draw[->, blue] (Tright) -- (Tright_text);
% Tleft
\node (Tleft_text) at (-4,-3) {$T_{\text{left}(\text{root})}$};
\node[draw=green, double, fit=(n4) (n5) (n6), inner sep=1ex, ellipse] (Tleft) {};
\draw[->, blue] (Tleft) -- (Tleft_text);
\end{forest}

broken link: file:~/brain/out/Yl6ICB.svg

  \begin{forest}
for tree={grow'=north}
[A
[B, edge label={node[midway,below,font=\scriptsize]{1}} [] [] [] [] [] [] [] [] [] []]
[C, edge label={node[midway,below,font=\scriptsize]{2}} [] [] [] [] [] [] [] [] [] []]
]
\end{forest}

broken link: file:~/brain/out/KYyGNeh.svg

! TeX capacity exceeded, sorry [save size=80000].

to get over this increase the value of save_size in kpsewhich texmf.cnf

calc projection

https://tex.stackexchange.com/questions/25342/how-to-draw-orthogonal-vectors-using-tikz
the projection syntax from the calc library also takes an optional angle: ($(A)!(P)!90:(B)$) is the projection of point (P) on the line from (A) to (B) after that line has been rotated 90 degrees around point (A). This makes it easy to draw the vector components:

  \begin{tikzpicture}
\node [dot=A,gray] at (1,4) {};
\node [dot=B,gray] at (2,2) {};
\node [dot=P] at (4,3) {};
\node [dot=P2,cyan] at (3,2.5) {};
\draw [->] (A) -- (B);
\draw [->,red] (A) -- ($(A)!(B)!(P)$);
\draw [->,red] (A) -- ($(A)!(B)!90:(P)$);
\draw [->,cyan] (A) -- ($(A)!(B)!(P2)$);
\draw [->,cyan] (A) -- ($(A)!(B)!90:(P2)$);
\end{tikzpicture}

animation

  \foreach \v in {0,0.5,...,5}
{
\begin{tikzpicture}
\draw[->] (-3, 0) -- (4.2, 0) node[right] {$x$};
\draw[->] (0, -3) -- (0, 4.2) node[above] {$y$};
\draw[scale=0.5, domain=-3:3, smooth, variable=\x, blue] plot ({\x+\v}, {\x*\x});
\draw[scale=0.5, domain=-3:3, smooth, variable=\y, red] plot ({\y*\y}, {\y+\v});
\end{tikzpicture}
}

broken link: file:~/brain/out/e3xkrhv.gif

neural network

  \colorlet{myred}{red!80!black}
\colorlet{myblue}{blue!80!black}
\colorlet{mygreen}{green!60!black}
\colorlet{myorange}{orange!70!red!60!black}
\colorlet{mydarkred}{red!30!black}
\colorlet{mydarkblue}{blue!40!black}
\colorlet{mydarkgreen}{green!30!black}
\tikzstyle{node}=[thick,circle,draw=myblue,minimum size=22,inner sep=0.5,outer sep=0.6]
\tikzstyle{node in}=[node,green!20!black,draw=mygreen!30!black,fill=mygreen!25]
\tikzstyle{node hidden}=[node,blue!20!black,draw=myblue!30!black,fill=myblue!20]
\tikzstyle{node convol}=[node,orange!20!black,draw=myorange!30!black,fill=myorange!20]
\tikzstyle{node out}=[node,red!20!black,draw=myred!30!black,fill=myred!20]
\tikzstyle{connect}=[thick,mydarkblue] %,line cap=round
\tikzstyle{connect arrow}=[-{Latex[length=4,width=3.5]},thick,mydarkblue,shorten <=0.5,shorten >=1]
\tikzset{ % node styles, numbered for easy mapping with \nstyle
node 1/.style={node in},
node 2/.style={node hidden},
node 3/.style={node out},
}
\def\nstyle{int(\lay<\Nnodlen?min(2,\lay):3)} % map layer number onto 1, 2, or 3
\begin{tikzpicture}[x=2.2cm,y=1.4cm]
\message{^^JNeural network with arrows}
\readlist\Nnod{3,5,5,5,2} % array of number of nodes per layer
\message{^^J Layer}
\foreachitem \N \in \Nnod{ % loop over layers
\edef\lay{\Ncnt} % alias of index of current layer
\message{\lay,}
\pgfmathsetmacro\prev{int(\Ncnt-1)} % number of previous layer
\foreach \i [evaluate={\y=\N/2-\i; \x=\lay; \n=\nstyle;}] in {1,...,\N}{ % loop over nodes
% NODES
\node[node \n] (N\lay-\i) at (\x,\y) {$a_\i^{(\prev)}$};
%\node[circle,inner sep=2] (N\lay-\i') at (\x-0.15,\y) {}; % shifted node
%\draw[node] (N\lay-\i) circle (\R);
% CONNECTIONS
\ifnum\lay>1 % connect to previous layer
\foreach \j in {1,...,\Nnod[\prev]}{ % loop over nodes in previous layer
\draw[connect arrow] (N\prev-\j) -- (N\lay-\i); % connect arrows directly
%\draw[connect arrow] (N\prev-\j) -- (N\lay-\i'); % connect arrows to shifted node
}
\fi % else: nothing to connect first layer
}
}
\end{tikzpicture}

broken link: file:/home/mahmooz/brain/out/DrBomTG.svg

turing machine

  % Turing Machine
% Author: Sebastian Sardina
\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
\usetikzlibrary{chains,fit,shapes}
\begin{document}
\begin{tikzpicture}
\tikzstyle{every path}=[very thick]
\edef\sizetape{0.7cm}
\tikzstyle{tmtape}=[draw,minimum size=\sizetape]
\tikzstyle{tmhead}=[arrow box,draw,minimum size=.5cm,arrow box
arrows={east:.25cm, west:0.25cm}]
%% Draw TM tape
\begin{scope}[start chain=1 going right,node distance=-0.15mm]
\node [on chain=1,tmtape,draw=none] {$\ldots$};
\node [on chain=1,tmtape] {};
\node [on chain=1,tmtape] (input) {b};
\node [on chain=1,tmtape] {b};
\node [on chain=1,tmtape] {a};
\node [on chain=1,tmtape] {a};
\node [on chain=1,tmtape] {a};
\node [on chain=1,tmtape] {a};
\node [on chain=1,tmtape] {};
\node [on chain=1,tmtape,draw=none] {$\ldots$};
\node [on chain=1] {\textbf{Input/Output Tape}};
\end{scope}
%% Draw TM Finite Control
\begin{scope}
[shift={(3cm,-5cm)},start chain=circle placed {at=(-\tikzchaincount*60:1.5)}]
\foreach \i in {q_0,q_1,q_2,q_3,\ddots,q_n}
\node [on chain] {$\i$};
% Arrow to current state
\node (center) {};
\draw[->] (center) -- (circle-2);
\node[rounded corners,draw=black,thick,fit=(circle-1) (circle-2) (circle-3)
(circle-4) (circle-5) (circle-6),
label=below:\textbf{Finite Control}] (fsbox)
{};
\end{scope}
%% Draw TM head below (input) tape cell
\node [tmhead,yshift=-.3cm] at (input.south) (head) {$q_1$};
%% Link Finite Control with Head
\path[->,draw] (fsbox.north) .. controls (4.5,-1) and (0,-2) .. node[right]
(headlinetext)
{}
(head.south);
\node[xshift=3cm] at (headlinetext)
{\begin{tabular}{c}
\textbf{Reading and Writing Head} \\
\textbf{(moves in both directions)}
\end{tabular}};
\end{tikzpicture}
\end{document}

heatmap

  \documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[scale=0.6]
\foreach \y [count=\n] in {
{74,25,39,20,3,3,3,3,3},
{25,53,31,17,7,7,2,3,2},
{39,31,37,24,3,3,3,3,3},
{20,17,24,37,2,2,6,5,5},
{3,7,3,2,12,1,0,0,0},
{3,7,3,2,1,36,0,0,0},
{3,2,3,6,0,0,45,1,1},
{3,3,3,5,0,0,1,23,1},
{3,2,3,5,0,0,1,1,78},
} {
% column labels
\ifnum\n<10
\node[minimum size=6mm] at (\n, 0) {\n};
\fi
% heatmap tiles
\foreach \x [count=\m] in \y {
\node[fill=yellow!\x!purple, minimum size=6mm, text=white] at (\m,-\n) {\x};
}
}
% row labels
\foreach \a [count=\i] in {a,b,c,d,e,f,g,h,i} {
\node[minimum size=6mm] at (0,-\i) {\a};
}
\end{tikzpicture}
\end{document}

dual graphs

\begin{tikzpicture}
\draw (0,0) grid (5,5);
\draw[densely dashed, shift={(-.5,-.5)}] (.1,.1) grid (5.9,5.9);
\draw[line width=3pt, line cap=round, dash pattern=on 0pt off 1cm](0,0) grid (5,5);
\draw[shift={(-.5,-.5)}, double, double distance=2.2pt, line cap=round, dash pattern=on 0pt off 1cm] (1,1) grid (5,5);
\end{tikzpicture}

\begin{tikzpicture}[
V/.style = {% V as Vortex
draw,circle,thick,fill=#1},
V/.default = black!20
]
\node[V] (A) at (0,0)[] {A};
\node[V] (B) at (3,0) {B};
\node[V] (C) at (6,-2) {C};
\node[V] (D) at (0,-4) {D};
\node[V] (E) at (3,-4) {E};
\begin{scope}[V/.default = green!20]
\node[V] (ABD) at (1.5,-1) {};
\node[V] (BDE) at (2,-3) {};
\node[V] (out) at (-2,2) {};
\node[V] (BCE) at (4.5,-2) {};
\end{scope}
%%graph G
\draw
(A) to ["$e_2$ 6",near end] (B)
(A) to ["$e_1$ 1" '] (D)
(D) to ["$e_5$ 2"] (B)
(D) to ["$e_4$ 1",near start] (E)
(E) to ["$e_6$ 2" ',near end] (B)
(E) to ["$e_7$ 5" ',near end] (C)
(B) to ["$e_3$ 5",near start] (C);
%%dual graph G*
\clip (-4,-6) rectangle + (10.5,9.2);% remove empty spaces caused by looseness option
%\draw (-4,-6) rectangle + (10.5,9.2); % to see clip border
\draw[dashed]
(ABD) to ["$e^*_5$ 2",near end] (BDE)
(ABD) to ["$e^*_2$ 6",bend right=50,swap,near end] (out)
(BDE) to ["$e^*_6$ 2" '] (BCE)
(BCE) to ["$e^*_3$ 5" ',bend right=100] (out)
(out) to ["$e^*_1$ 1" ',bend right=50] (ABD)
(out) to ["$e^*_7$ 5" ', out=-135,in=-105,looseness=2.7] (BCE)
(out) to ["$e^*_4$ 1" , out=-135,in=-120,looseness=2.2] (BDE);
\end{tikzpicture}

other

\usetikzlibrary{calc,backgrounds}
\definecolor{aquamarine}{HTML}{008B9B}
\tikzset{my node/.style={draw,circle,fill=white,inner sep=0,minimum size=9mm}}
\begin{document}
\begin{tikzpicture}
\def\a{4.5} % a semiaxis
\def\b{2.25} % b semiaxis
\def\h{2.5} % height
\foreach[count=\jj from 0]\j in {L,R} % left, right
{
\begin{scope}[shift={({2*\jj*(\a+0.5)},0)}]
\foreach[count=\ii]\i in {130,210,250,290,330}
{% nodes 1 to 5
\node[my node] (\j B\ii) at (\i:\a cm and \b cm) {$\ii'$};
\node[my node,yshift=\h cm] (\j T\ii) at (\i:\a cm and \b cm) {$\ii$};
}% nodes 6 and 7
\node[my node] (\j B6) at (50:\a cm and \b cm) {};
\node[my node,yshift=\h cm] (\j T6) at (50:\a cm and \b cm) {};
\node[my node] (\j B7) at (90:\a cm and \b cm) {$(2n)'$};
\node[my node,yshift=\h cm] (\j T7) at (90:\a cm and \b cm) {$(2n)$};
\foreach\i in {1,...,7}% vertical lines
\draw (\j B\i) -- (\j T\i);
\foreach\i in {2,4}% middle height nodes
\node[my node] at ($(\j B\i)!0.5!(\j T\i)$) {\pgfmathparse{int(\i/2)}$\bar\pgfmathresult$};
\node[rotate=-10] at ($(\j B6) !0.5!(\j T7)$) {$\cdots$}; % dots
\end{scope}
}
% ellipses
\begin{scope}[on background layer]
\draw[very thick,red] (0,0) ellipse (\a cm and \b cm);
\draw[very thick,aquamarine] (0,\h) ellipse (\a cm and \b cm);
\draw[very thick,red] (RT7) -- (RB1.center) arc (130:450:\a cm and \b cm);
\draw[very thick,aquamarine] (RB7) -- (RT1.center) arc (130:450:\a cm and \b cm);
\end{scope}
\end{tikzpicture}
\end{document}

  \documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[scale=1.5]
\tikzset{unode/.style = {
circle,
draw=cyan!30!black,
thick,
fill=cyan!80!black,
inner sep=2.3pt,
minimum size=2.3pt } }
\tikzset{uedge/.style = {
draw=cyan!20!black,
very thick} }
\node[unode] (o1) at (90:3) {};
\node[unode] (o2) at (210:3) {};
\node[unode] (o3) at (330:3) {};
\foreach \x in {1,2,3,4,5,6}{
\node[unode] (i\x) at (-30+\x*60:1) {};
}
\node[unode] (ii1) at (150:0.4) {};
\node[unode] (ii2) at (30:0.4) {};
\node[unode] (ii3) at (270:0.4) {};
\path[uedge] (o1) -- (o2) -- (o3) -- (o1);
\path[uedge] (ii1) -- (ii2) -- (ii3) -- (ii1);
\path[uedge] (i1) -- (i2) -- (i3) -- (i4)--(i5)--(i6)--(i1);
\path[uedge] (o1) edge (i2) edge (i1) edge(i3);
\path[uedge] (o2) edge (i3) edge (i4) edge(i5);
\path[uedge] (o3) edge (i1) edge (i5) edge(i6);
\path[uedge] (i2) edge (ii1) edge (ii2);
\path[uedge] (i4) edge (ii1) edge (ii3);
\path[uedge] (i6) edge (ii2) edge (ii3);
\path[uedge] (i1) edge (ii2);
\path[uedge] (i3) edge (ii1);
\path[uedge] (i5) edge (ii3);
\end{tikzpicture}
\end{document}

  \draw [red, fill=white] \pgfextra{
\pgfpathellipse{\pgfplotspointaxisxyz{5}{12}{18}}
{\pgfplotspointaxisdirectionxyz{0}{3}{0}}
{\pgfplotspointaxisdirectionxyz{0}{0}{3}}
};
\node[] at (5,12,18) {$1$};

the source also provides code for generating an animation of this
  \documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\makeatletter
\pgfqkeys{/tikz/cs}{ % https://tex.stackexchange.com/a/114158/121799
latitude/.store in=\tikz@cs@latitude,% not needed with '3d' library
longitude/.style={angle={#1}},% not needed with '3d' library
theta/.style={latitude={#1}},
rho/.style={angle={#1}}
}
\tikzdeclarecoordinatesystem{xyz spherical}{% needed even with '3d' library!
\pgfqkeys{/tikz/cs}{angle=0,radius=0,latitude=0,#1}%
\pgfpointspherical{\tikz@cs@angle}{\tikz@cs@latitude}{\tikz@cs@xradius}% fix \tikz@cs@radius to \tikz@cs@xradius
}
\makeatother
\tdplotsetmaincoords{70}{155}
\begin{document}
\begin{tikzpicture}
\def\RadiusSphere{3}
\shade[ball color = gray!40, opacity = 0.5] (0,0) circle (\RadiusSphere);
\begin{scope}[tdplot_main_coords]
% comment these out if you want to know where the axes point
% \draw[->] (0,0,0) -- ({1.2*\RadiusSphere},0,0) coordinate(Y) node[below] {$x$};
% \draw[->] (0,0,0) -- (0,{1.2*\RadiusSphere},0) coordinate(Z) node[below] {$y$};
% \draw[->] (0,0,0) -- (0,0,{2.2*\RadiusSphere}) coordinate(X) node[left] {$z$};
% middle triangle
\draw plot[variable=\x,domain=-20:20]
(xyz spherical cs: radius=\RadiusSphere,angle=\x,latitude=0);
\draw plot[variable=\x,domain=0:40]
(xyz spherical cs: radius=\RadiusSphere,angle={20-\x/2},latitude={\x*tan(60)/2}) ;
\draw plot[variable=\x,domain=0:40]
(xyz spherical cs: radius=\RadiusSphere, angle={-20+\x/2},latitude={\x*tan(60)/2}) ;
\node at (xyz spherical cs: radius=\RadiusSphere,angle=0,latitude={20/sqrt(3)}) {$F_1$};
% bottom 4-angle (these are not rectangles on a sphere ;-)
\draw plot[variable=\x,domain=00:-40]
(xyz spherical cs: radius=\RadiusSphere, angle=20,latitude=\x);
\draw plot[variable=\x,domain=00:-40]
(xyz spherical cs: radius=\RadiusSphere, angle=-20,latitude=\x);
\draw plot[variable=\x,domain=-20:20]
(xyz spherical cs: radius=\RadiusSphere, angle=\x,latitude=-40);
\node at (xyz spherical cs: radius=\RadiusSphere,angle=0,latitude=-20) {$F_4$};
% left 3-angle
\draw plot[variable=\x,domain=00:40]
(xyz spherical cs:
radius=\RadiusSphere,angle={20+\x*sin(60)},latitude={\x*cos(60)}) ;
\draw plot[variable=\x,domain=00:40]
(xyz spherical cs:
radius=\RadiusSphere,angle={20+40*sin(60)-\x/2},latitude={40*cos(60)+\x*tan(60)/2}) ;
\draw plot[variable=\x,domain=00:40]
(xyz spherical cs:
radius=\RadiusSphere,angle={\x*sin(60)},latitude={40*tan(60)/2+\x*cos(60)}) ;
\node at (xyz spherical cs: radius=\RadiusSphere,angle={20+10*sin(60)},
latitude={20+20*cos(60)/sqrt(3)}) {$F_2$};
% right 4-angle
\draw plot[variable=\x,domain=00:40]
(xyz spherical cs:
radius=\RadiusSphere,angle={-20-\x*sin(60)},latitude={\x*cos(60)}) ;
\draw plot[variable=\x,domain=00:40]
(xyz spherical cs:
radius=\RadiusSphere,angle={-20-40*sin(60)+\x/2},latitude={40*cos(60)+\x*tan(60)/2}) ;
\draw plot[variable=\x,domain=00:40]
(xyz spherical cs:
radius=\RadiusSphere,angle={-\x*sin(60)},latitude={40*tan(60)/2+\x*cos(60)}) ;
\node at (xyz spherical cs: radius=\RadiusSphere,angle={-20-10*sin(60)},
latitude={20+20*cos(60)/sqrt(3)}) {$F_3$};
\end{scope}
\end{tikzpicture}
\end{document}

  \documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[%
every node/.style={draw,fill=gray!40,circle,minimum size=18pt,font=\footnotesize},
node distance=3cm,on grid]
% the vertices
\node[label=left:Source] (source) at (0,0) {1};
\node[right=of source] (three) {3};
\node[above=of three] (two) {2};
\node[below=of three] (four) {4};
\node[right=of source] (three) {3};
\node[right=of three] (six) {6};
\node[above=of six] (five) {5};
\node[below=of six] (seven) {7};
\node[right=of six,label=right:Sink] (sink) {8};
\node at (1.9,1) (sfive) {$5^*$};
\node at (4.5,1) (sseven) {$7^*$};
\node at (7.1,1) (ssix) {$6^*$};
\node at (1.9,-1) (sthree) {$3^*$};
\node at (4.5,-1) (stwo) {$2^*$};
\node at (7.1,-1) (sfour) {$4^*$};
\node at (4.5,4) (seight) {$8^*$};
\node at (4.5,-4) (sone) {$1^*$};
% the edges
\draw (source) -- (two) -- (five) -- (sink) -- (seven) -- (four) -- (source) -- (three) -- (six) -- (sink);
\draw (two) -- (three) -- (four);
\draw (five) -- (six) -- (seven);
\begin{scope}[dashed]
\draw (sfive) -- (sseven) -- (ssix) -- (sfour) -- (stwo) -- (sthree) -- (sfive);
\draw (sthree) to [bend right=55] (sone);
\draw (sfour) to [bend left=55] (sone);
\draw (sfive) to [bend left=55] (seight);
\draw (ssix) to [bend right=55] (seight);
\draw (source) .. controls (1,-6.5) and (8,-6.5) .. node[draw=none, fill=none,label=above:$s^*$] {} (sink);
\end{scope}
\end{tikzpicture}
\end{document}