# How to draw path of contour integral enclosing imaginary axis

I have practically no experience with Tikz but was able to piece together this diagram of a contour integral enclosing the imaginary axis.

It was produced with this code.

\documentclass[tikz,svgnames]{standalone}

\usepackage{mathtools}
\DeclareMathOperator{\im}{Im}
\DeclareMathOperator{\re}{Re}

\begin{document}
\begin{tikzpicture}[thick]
% Axes:
\draw [->] (-5,0) -- (5,0) node [above left]  {$\re(p_0)$};
\draw [->] (0,-4.7) -- (0,4.7) node [below left = -1pt] {$\im(p_0)$};

% Axes labels:
\foreach \n in {-4,...,-1,1,2,...,4}{%
\draw[fill] (0,\n) circle (1pt) node [right] {$i \omega_{_{\n}}$};
}
\draw[fill] (0,0) circle (1pt) node [above right] {0};

% Contour line
\draw[DarkBlue]
(1,-4) -> (1,4) node [below right] {$C$} arc (0:180:1) (-1,4) -- (-1,-4) arc (180:360:1);

\draw[fill] (3,2) circle (1pt) node [pin={above:poles of $h(p_0)$}] {};
\draw[fill] (2,-2) circle (1pt) node [pin={above right:poles of $h(p_0)$}] {};

\end{tikzpicture}
\end{document}


There are a few things I'm still struggling with.

1. I would like the two half arcs at the top and bottom to be dashed but the vertical lines connecting them to remain solid.
2. The two pins labelling dots outside the contour with poles of h(p0) should be just one pin with lines pointing to both dots.
3. I'd like Im(p0) to be further removed from the imaginary axis but connected by a thin line just like the pins.
4. The contour should be decorated by a few arrows pointing in the counterclockwise direction.

Like this?

\documentclass[tikz,svgnames,border=3mm]{standalone}
\usetikzlibrary{decorations.markings, positioning}
\usepackage{mathtools}
\DeclareMathOperator{\im}{Im}
\DeclareMathOperator{\re}{Re}

\begin{document}
\begin{tikzpicture}[thick,
decoration={
markings,% switch on markings
mark=at position .75 with {\arrow{>}}}
]
% Axes:
\draw [->] (-5,0) -- (5,0) node [above left]  {$\re(p_0)$};
\draw [->] (0,-4.7) -- (0,4.7) node [below left = -1pt and 11mm] {$\im(p_0)$};

% Axes labels:
\foreach \n in {-4,...,-1,1,2,...,4}{%
\draw[fill] (0,\n) circle (1pt) node [right] {$i \omega_{_{\n}}$};
}
\draw[fill] (0,0) circle (1pt) node [above right] {0};

% Contour line
\draw[DarkBlue,postaction={decorate}]   ( 1,-4) -- ( 1, 4) node [below right] {$C$};
\draw[DarkBlue,postaction={decorate}]   (-1, 4) -- (-1,-4);
\draw[DarkBlue,dashed]                  (1,4) arc (0:180:1) (-1,4)  (-1,-4) arc (180:360:1);

\draw[fill] (3, 2) circle (1pt) node[below right=2mm and 9mm] (h0) {poles of $h(p_0)$}
(2,-2) circle (1pt);
\draw[thin, shorten >=1mm] (h0.west) --  (3,2) (h0.south west) -- (2,-2);
\end{tikzpicture}
\end{document}


\documentclass[tikz,svgnames,border=3mm]{standalone}
\usetikzlibrary{decorations.markings, positioning}
\usepackage{mathtools}
\DeclareMathOperator{\im}{Im}
\DeclareMathOperator{\re}{Re}

\begin{document}
\begin{tikzpicture}[thick,
decoration={
markings,% switch on markings
mark=at position .75 with {\arrow{>}}},
every pin/.append style = {pin distance=11mm, pin edge={<-,black}}% added
]
% Axes:
\draw [->] (-5,0) -- (5,0) node [above left]  {$\re(p_0)$};
\draw [->] (0,-4.7) -- (0,4.7) node [below left, pin=left: $\im(p_0)$] {};% changed
% Axes labels:
\foreach \n in {-4,...,-1,1,2,...,4}{%
\draw[fill] (0,\n) circle (1pt) node [right] {$i \omega_{_{\n}}$};
}
\draw[fill] (0,0) circle (1pt) node [above right] {0};
% Contour line
\draw[DarkBlue,postaction={decorate}]   ( 1,-4) -- ( 1, 4) node [below right] {$C$};
\draw[DarkBlue,postaction={decorate}]   (-1, 4) -- (-1,-4);
\draw[DarkBlue,dashed]                  (1,4) arc (0:180:1) (-1,4)
(-1,-4) arc (180:360:1);

\draw[fill] (3, 2) circle (1pt) node[below right=2mm and 9mm] (h0) {poles of $h(p_0)$}
(2,-2) circle (1pt);
\draw[thin, shorten >=1mm] (h0.west) --  (3,2) (h0.south west) -- (2,-2);
\end{tikzpicture}
\end{document}


• Looks great! That's exactly what I had in mind, except for one detail. Do you know how to draw a thin line from Im(p0) to its axis? Nov 3 '16 at 11:11
• Also, is there no way to have parts of the contour dashed and parts solid without breaking it up into multiple \draw commands? Nov 3 '16 at 11:13
• (i) to my opinion is better move node closer to y-axis so, that it is inside integral contour .... other wise you can draw line on the same way as it is for poles h(0), (ii) it is possible only with broke line to several parts. If the dashed line parts are on their end, tha they can be joined with arcs. Nov 3 '16 at 14:38