Vladimir Vargas Vladimir Vargas - 4 months ago 45
Python Question

Hide radial tick labels matplotlib

I'm trying to plot a polar plot with this code:

import numpy as np
import matplotlib.pylab as plt
def power(angle, l, lam):
return 1/(lam) * ((np.cos(np.pi*l*np.cos(angle)/lam) - np.cos(np.pi*l/lam))/np.sin(angle))**2
fig = plt.figure(1)
ax = fig.add_subplot(111, projection='polar')
theta = np.linspace(0.001, 2*np.pi, 100)
P1 = power(theta, 1, 5)
ax.plot(theta, P1, color='r', linewidth=3)

and I get this plot:

enter image description here

I would like to change 2 things. The first and more important one is to hide the radial tick labels (I just want to show the general form of the plot).

If possible, how can I choose the vertical axis to correspond to 0°?

Thanks for your help.


You can use set_yticklabels() to remove the radial ticks and set_theta_zero_location() to change the zero location:

fig = plt.figure(1)
ax = fig.add_subplot(111, projection='polar')
ax.plot(theta, P1, color='r', linewidth=3)

You might also want to change the direction of the azimuthal axis: