The example code creates a 2D visualization of angles relative to the center. Contour lines with labels are added to show lines of constant angle.
import numpy as np
import matplotlib.pyplot as plt
n = 200
x = np.arange(n)
y = np.arange(n)
X, Y = np.meshgrid(x, y)
Z = np.arctan2(Y-n/2, X-n/2)
plt.imshow(Z, cmap='twilight')
contours = plt.contour(X, Y, Z)
plt.clabel(contours)
plt.show()
You can see that all contours are overlapping at the negative x-axis, which corresponds to an angle of π of -π. How can I prevent this and only plot one contour line?

2piacross the x-axis. So as far as the program is concerned the contours are very tightly spaced there - i.e. sat on top of each other. It also looks slightly twisted and warped near the origin viewed at full resolution. The contour lines to the negative side of the origin are 1 or 2 pixels too high.