I just stumpled upon it and it made me curious. Why is the imaginary part of $\ln(\Gamma(x))$ a square wave for $x < 0$ ? The square wave has a period of 2 and a amplitude of $\pi/2$. How can one explain this regular structure?

I just stumpled upon it and it made me curious. Why is the imaginary part of $\ln(\Gamma(x))$ a square wave for $x < 0$ ? The square wave has a period of 2 and a amplitude of $\pi/2$. How can one explain this regular structure?

On
About the logarithm of the Gamma function you find here.
Note that the Gamma function has poles on $-1,-2,-3,...$; These poles are dominating also in the logarithm of the Gamma functions.
If $\newcommand{\real}{\operatorname{Re}}\real z > 0$, $$ \Gamma(z) = \int_0^{\infty} z^{t-1}e^{-z}\,dz. $$ In particular, if $x$ is positive real, then $\Gamma(x)$ is also positive real. By analytic continuation, $\Gamma$ can be extended to a meromorphic function on $\mathbb{C}$. For example, it can be shown that Euler's reflection forumla: $$ \Gamma(1-z)\Gamma(z) = \frac{\pi}{\sin \pi z} $$ holds. In particular, if we take $z$ real and $z > 1$, we see that the $\Gamma$ function is real valued on the whole real axis. (With poles at the negative integers.) Furthermore, the sign of $\Gamma(z)$ flips at the negative integers because of the sign changes of $\sin \pi z$: for $-1 < x < 0$, $\Gamma(x) < 0$. For $-2 < x < -1$, $\Gamma(x) > 0$ and so on. Here is a graph of $\Gamma(x)$ for real $x$:
Finally, $\operatorname{Im} \log \Gamma(x)$ is just the argument of $\Gamma(x)$ as a complex number. (See this description.) The program you are using to create the plot seems to be using a branch of the complex logarithm where the argument of a negative real number is $\pi$. (Often, the complex logarithm is left undefined on the negative real axis.)
In other words, $\operatorname{Im} \log \Gamma(x)$ will be $0$ when $\Gamma(x)$ is positive, and $\pi$ when $\Gamma(x)$ is negative.