2016-11-28 167 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找到。