# TikZ plot dealing with infinities

I have a couple of problems while drawing a picture with TikZ. The picture I would like to obtain is like the following:

.

Here is my code:

\documentclass[10pt]{article}
\usepackage{pgf,tikz}
\usetikzlibrary{positioning,patterns}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[scale=2]
\clip(0,0) rectangle (6,6);
\draw[thick] (3.,3.) circle ({pi/2});
\pgfmathsetmacro{\x}{1};
\draw[thick,pattern=north west lines, pattern color=black] (3.,3.) circle ({rad(atan(\x))});
\begin{scope}[shift={(3,3)}]
\foreach \z in {0.5,1,2,3}
\end{scope}
\end{tikzpicture}
\end{document}


What I obtain is

I have two problems:

• I have infinities in my calculation. That gave all sort of problems, so I restricted the domain in the plot so that I don't include the singular point (which then is mapped to a finite value by the arctan function). However, in this way I cannot get to the proper value and the plots do not touch the outer circle.
• The plot lines are not smooth.

Any ideas on how to solve this?

• By default when you draw something TikZ use 25 points. You can change this by putting for example samples=300 in your \draw command. This will smooth the curve. – Kpym Dec 14 '14 at 11:41
• You can solve your first problem by cheating : make your circle a little bit smaller (and clip with it). – Kpym Dec 14 '14 at 11:42
• or if you want less accuracy but faster compile you can put less points (for example samples=100), but add smooth and play with tension. – Kpym Dec 14 '14 at 12:00

Takes a bit to compile but looks like it comes close. I used pgfplots to handle the plotting and infinity issues etc. It already provides a polaraxis environment so no need to do extra work. You can also invoke a gnuplot directive to get more precision. I would strongly recommend changing the colormap though. Even Matlab finally stopped using it in 2014b.

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{patterns,pgfplots.polar}
\begin{document}
\begin{tikzpicture}
\begin{polaraxis}[samples=200,grid=none,enlargelimits=false,
xtick=\empty,ytick=\empty,axis y line={none}]
\pgfmathsetmacro{\x}{1};
\pgfplotsinvokeforeach{0.15,0.3,...,3,pi}{
point meta=12-\plotnumofactualtype, % For color match
point meta max=30]
\end{polaraxis}
\end{tikzpicture}
\end{document}


• the lines are not touching the boundary. A little bit smaller circle (with clip) will be ok. I have not investigated if this is a precision problem or something else, I'm just looking and admiring your picture ! – Kpym Dec 14 '14 at 15:46
• @Kpym You can add ymax=1.4. Because it is an axis, it will limit the visible area. – percusse Dec 14 '14 at 17:49

This is a cheating lesson (you can see my comments), not a real solution.

\documentclass[varwidth,border=50]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,patterns}

\begin{document}
\begin{tikzpicture}[scale=2]
\clip (3.,3.) circle ({pi/2 - .05});
\pgfmathsetmacro{\x}{1};
\draw[thick,pattern=north west lines, pattern color=black] (3.,3.) circle ({rad(atan(\x))});
\begin{scope}[shift={(3,3)}]
\foreach[evaluate=\z as \c using .3*\z] \z in {.1,.3,...,3,3.14} {
\definecolor{currentcolor}{hsb}{\c,1,1}
\draw [variable=\y,domain=-\z+0.001:\z-0.001, smooth, samples=100, currentcolor]
}
\end{scope}
\draw[very thick] (3.,3.) circle ({pi/2 - .059});
\end{tikzpicture}
\end{document}


EDIT: And here is a real solution using atan2 to avoid infinity problems.

\documentclass[varwidth,border=50]{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns}

\begin{document}
\begin{tikzpicture}[scale=2]
\draw[thick,pattern=north west lines, pattern color=black] circle (pi/4);
\foreach[
evaluate=\z as \c using \z/180,