简体   繁体   中英

Matplotlib polar plot is not plotting where it should

I try to represent spherical coordinates azimuth and elevation in degrees in a polar plot. I have a set of values to test for 0, 90, 180 and 270 degrees, and it is clearly seen that they are not plotted at the azimuth value they should.

Code:

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')

And this is the result, clearly imprecise: 在此处输入图片说明

I have changed the axis so they start at 0 degrees and then go clockwise, and the radius represents the elevation (from 90º at the circle center, until 0º at the border).

Late, but:

Code:

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')

Result:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM