""" inconsistent_angle_units.py OVERVIEW This Python script demonstrates one of the more unusual matplotlib anomalies: When one produces a polar contour plot, the 'y' axis (circumferential axis) labels are displayed in degrees while the 'x' axis (radial axis) labels are displayed in radians! AUTHOR Phillip M. Feldman """ from matplotlib import pyplot from numpy import arccos, array, cos, linspace, meshgrid, pi, sin, sqrt, where # Generate the data: cone = (pi/180.) * linspace(0, 90, num= 91, endpoint=True)[None, :] clock= (pi/180.) * linspace(0, 360, num=121, endpoint=True)[:, None] denom= sqrt(sin(cone)**2 * cos(clock)**2 + cos(cone)**2) azim= (180./pi) * arccos(cos(cone)/denom) azim= where((clock > 0.5*pi) & (clock < 1.5*pi), -azim, azim) cone, clock= meshgrid(cone.ravel(), clock.ravel()) # Plot the data: levels= [-90, -85] + range(-80, 81, 10) + [85, 90] figure= pyplot.figure(facecolor=[1, 1, 1], figsize=(9, 10)) axes= figure.add_subplot(111, projection='polar') contour= axes.contourf(clock, cone, azim, levels=levels) # Increase size of tick labels: for tick in axes.xaxis.get_major_ticks(): tick.label.set_fontsize(18) for tick in axes.yaxis.get_major_ticks(): tick.label.set_fontsize(18) axes.set_title('Strange matplotlib behavior', fontsize=22, y=1.08) axes.grid(False) pyplot.show() figure.savefig("inconsistent_angle_units.png")