python - Matplotlib 极坐标图未绘制在应有的位置

标签 python matplotlib

我尝试在极坐标图中表示球坐标方位角和仰角(以度为单位)。我有一组值来测试 0、90、180 和 270 度,可以清楚地看到它们没有绘制在应有的方位角值处。

代码:

from matplotlib.pyplot import rc, grid, figure, plot, rcParams, savefig


def generate_satellite_plot(observer_lat, observer_lon):
    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 = 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')
    ax.set_theta_zero_location('N')
    ax.set_theta_direction(-1)

    sat_positions = [[1, 30, 0], [2, 60, 90], [3, 30, 180], [4, 50, 270]]
    for (PRN, E, Az) in sat_positions:
        ax.annotate(str(PRN),
                    xy=(Az, 90-E),  # theta, radius
                    bbox=dict(boxstyle="round", fc = 'green', alpha = 0.5),
                    horizontalalignment='center',
                    verticalalignment='bottom')


    ax.set_yticks(range(0, 90, 10))                   # Define the yticks
    yLabel = ['90', '', '', '60', '', '', '30', '', '', '']
    ax.set_yticklabels(yLabel)
    grid(True)

    savefig('foo.png')

这就是结果,显然不精确: enter image description here

我更改了轴,使它们从 0 度开始,然后顺时针旋转,半径表示高程(从圆中心的 90° 到边界的 0°)。

最佳答案

迟到了,但是:

代码:

from matplotlib.pyplot import rc, grid, figure, plot, rcParams, savefig
from math import radians

def generate_satellite_plot(observer_lat, observer_lon):
    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 = 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')
    ax.set_theta_zero_location('N')
    ax.set_theta_direction(-1)

    sat_positions = [[1, 30, 0], [2, 60, 90], [3, 30, 180], [4, 50, 270]]
    for (PRN, E, Az) in sat_positions:
        ax.annotate(str(PRN),
                    xy=(radians(Az), 90-E),  # theta, radius
                    bbox=dict(boxstyle="round", fc = 'green', alpha = 0.5),
                    horizontalalignment='center',
                    verticalalignment='center')


    ax.set_yticks(range(0, 90+10, 10))                   # Define the yticks
    yLabel = ['90', '', '', '60', '', '', '30', '', '', '']
    ax.set_yticklabels(yLabel)
    grid(True)

    savefig('foo.png')

结果:

enter image description here

关于python - Matplotlib 极坐标图未绘制在应有的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18721762/

相关文章:

python - 从字符串的前面剥离 '../'

python - 如何在一个图中制作超过 10 个子图?

python - matplotlib 绘图然后等待原始输入

python - 在 matplotlib 中绘制具有固定限制的自动缩放子图

python - 缓存(假)静态内容,实际上在 GAE for Python 上是动态的

python - 使用 PySCIPOpt 设置 MIP 终止间隙

numpy - 将 2D NumPy 数组转换为用于绘制直方图的一维数组

python - Matplotlib 设置单独的刻度样式

python - 在 Python 中使用 os.walk

python - 什么时候应该使用 "if"检查错误,什么时候应该使用异常?