2016-11-28 68 views
2

我试图绘制与此代码的极坐标图:隐藏径向刻度标记matplotlib

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) 
plt.savefig('1.png') 

,我得到这个情节:

enter image description here

我想换两件事情。第一个也是更重要的一个是隐藏放射状的刻度标签(我只是想显示一般的情节形式)。

如果可能,我如何选择垂直轴以对应0°?

感谢您的帮助。

回答

5

您可以使用set_yticklabels()删除径向蜱set_theta_zero_location()改变零点的位置:

fig = plt.figure(1) 
ax = fig.add_subplot(111, projection='polar') 
ax.plot(theta, P1, color='r', linewidth=3) 
ax.set_yticklabels([]) 
ax.set_theta_zero_location('N') 
plt.show() 

您可能还需要改变方位轴的方向:

ax.set_theta_direction(-1) 
1

你可以用ax.set_theta_zero_location('N')设置theta零位。

要修改将R刻度标记,你可以,如果你想将其彻底删除,请ax.set_yticklabels([])这样做

for r_label in ax.get_yticklabels(): 
    r_label.set_text('') 

更多的方法可以在the PolarAxes documentation找到。

相关问题