Phase of a mass spring damper system versus frequency ratio 
Equation 2.40 referred to in the caption is

But a plot of $\theta$ looks completely different from the above figure since the arctangent function ranges from -pi/2 to pi/2 whereas the angle in the figure ranges from 0 to pi. For example, I plotted
the function $\arctan{0.2x/(1-x^2)}$ but it looks completely different from the plot for the case when the damping ratio is 0.1 in the figure. Also as r becomes larger the argument of the arctangent function approaches 0 so the phase should approach 0 but the phase in the figure approaches $\pi$ as r becomes larger. Can someone explain why this is the case?
 A: This is more of a computer science question, but it's also something that I find physics students get confused by quite often and it doesn't seem to be mentioned as often as it should be, so I'm not voting to close it.
Basically, you're using the wrong arctan function to plot your results. If you use the right one, everything checks out. The arctan function is strange: in general, if $$\theta = \arctan\left(\frac{y}{x}\right), \tag{1} \label{1}$$ unlike most other inverse trigonometric functions that we're used to, the information about which quadrant $y$ and $x$ lie in is important and changes the answer! As a result one needs to use an arctan function with two arguments: one for $x$ and one for $y$. As a quick example, consider the following two possibilities for $\theta$:

*

*$\theta$ is the angle from the $x$ axis to the vector $(1,1)$

*$\theta$ is the angle from the $x$ axis to the vector $(-1,-1)$
If you use the formula given above for both these cases, you'd get the same angle ($45^\circ$), but it should be obvious that that's only the answer for Case (1). For Case (2) the answer should be $135^\circ$!
The point is that Equation (\ref{1}) only works when $x>0$. In your case, since $r$ goes from $0$ to $2$, the denominator certainly isn't positive for many of the parameters, so you can't naively use the default arctan function when plotting your results. Most (all?) programming languages have an implementation of a "2-argument arctangent" function, usually called the atan2 function. The Wikipedia page explains why it exists in more detail.
So you should use the "atan2" function of your plotting software. A tiny side-note: keep in mind that the atan2 functions usually accept arguments as $\texttt{atan2(x,y)}$, so the denominator comes first.  Below are some graphs using the Mathematica (Mathematica's $\texttt{ArcTan}$ function accepts either one or two arguments: the two argument case is equivalent to the atan2 function):

Mathematica Code:
f[z_] := ArcTan[ 1 - r^2, 2*z*r]

Plot[{f[0.1], f[0.25], f[0.5], f[0.7]}, {r, 0, 2}, PlotStyle -> {Black, {Gray , DotDashed}, {Gray, Dashed}, {Gray, Dotted}}, AxesLabel -> {"r", "\[Theta](r}"}]

