2012-10-18 103 views
1

我想用Python和matplotlib將一些代表可見衛星的值繪製成極座標圖。我已經寫了下面的一個matplotlib例如一些代碼,和極座標圖來表示,但由於點不是畫在:在matplotlib中繪製一些極座標圖的值

import matplotlib 
from matplotlib.pyplot import figure, show, rc, grid 
from math import pi 

# radar green, solid grid lines 
rc('grid', color='#316931', linewidth=1, linestyle='-') 
rc('xtick', labelsize=15) 
rc('ytick', labelsize=15) 

# force square figure and square axes looks better for polar, IMO 
width, height = matplotlib.rcParams['figure.figsize'] 
size = min(width, height) 
# make a square figure 
fig = figure(figsize=(size, size)) 
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True, axisbg='#d5de9c') 

# Satellite info [PRN, E, Az, Ss, Used (1 yes, 0 no)] 
sat = [ [1, 62, 255, 46, 1], 
     [14, 62, 26, 46, 1], 
     [31, 42, 158, 36, 1], 
     [22, 40, 76, 50, 1], 
     [11, 29, 308, 0, 0], 
     [19, 26, 243, 36, 1], 
     [3, 13, 217, 0, 0], 
     [18, 10, 93, 0, 0], 
     [20, 6, 291, 0, 0], 
     [5, 1, 72, 0, 0], 
     [122, 43, 216, 0, 0], 
     [135, 47, 203, 43, 0] ] 

for index in (0, len(sat)-1): 
    if(sat[index][4]>0): 
     ax.plot(sat[index][2], sat[index][1], color='green', marker='s', markersize=12) 
    else: 
     ax.plot(sat[index][2], sat[index][1], color='gray', marker='s', markersize=12) 

ax.set_rmax(2.0) 
grid(True) 

ax.set_title("Visible satellites", fontsize=20) 
show() 

我在做什麼錯?

回答

1

它只是遍歷你喜歡這個SATS的名單:

for s in sat: 
    if(s[4]>0): 
     ax.plot(s[2], s[1],color='green', marker='s', markersize=5) 
    else: 
     ax.plot(s[2], s[1],color='gray', marker='s', markersize=5) 

除此之外,你還限制了方位角< 2與set_rmax,這樣,只有1衛星可見,取消註釋以查看全部。

編輯: 直接拆包列表可能會進一步提高可讀性:

for (PRN, E, Az, Ss, Used) in sat: 
    if(Used>0): 
     ax.plot(Ss, Az,color='green', marker='s', markersize=5) 
    else: 
     ax.plot(Ss, Az,color='gray', marker='s', markersize=5) 
+0

我喜歡直接拆包。我不知道Python有什麼可能!謝謝! :) –

+0

問題是你說的set_rmax。我還有一個疑問:是否可以爲每個代表點添加一個標籤? –

+1

當然,您可以調用ax上的.text方法,因爲如果(Used> 0): ax,那麼上面的代碼將變爲: 'for(PRN,E,Az,Ss,Used)。繪圖(Ss,Az,顏色='灰色',標記='s',標記尺寸= 5)012.png(Ss,Az,color ='green',marker ='s',markersize = 5) else: ax.plot (Ss,Az,PRN,color ='red',size = 15)' –

1

在這一行:

for index in (0, len(sat)-1): 

指數只運行在一對值。你的意思是範圍for index in range(0, len(sat))?簡單