Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在matplotlib中将某些值打印到极坐标图_Python_Matplotlib - Fatal编程技术网

Python 在matplotlib中将某些值打印到极坐标图

Python 在matplotlib中将某些值打印到极坐标图,python,matplotlib,Python,Matplotlib,我想用Python和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, line

我想用Python和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()
我做错了什么?

在这行:

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

索引只在一对值上运行。您是指范围(0,len(sat))中的索引的范围

像这样迭代sat列表更简单:

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)

除此之外,你还限制了方位角,我喜欢直接拆包。我不知道Python有什么可能!谢谢!:)正如你所说,问题出在设定值上。我还有一个额外的疑问:是否可以为每个表示的点添加一个标签?当然,您可以在ax上调用.text方法,因为上面的代码将变成:
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)ax.text(Ss,Az,PRN,color='red',size=15)
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)