1

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: enter image description here

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

4
  • 3
    This is not a case of degrees versus radians? I don't know mpl polar plots by heart, but since '1' is at the right angle, and the angles between consecutives satellite positions are the same (just not 90 degrees), it looks like it. Unless, of course, you're not talking about the angles being imprecise. Commented Sep 10, 2013 at 14:41
  • @Evert, you are correct. theta is in radians instead of degrees. Converting to radians with degree * (pi / 180.) will lead to the correct results. Commented Sep 10, 2013 at 14:44
  • You might also want to use ax.set_yticks(range(0, 100, 10)) to make the alt=0 (at r=90) tick show. Commented Sep 10, 2013 at 14:49
  • 1
    @Evert That's right. I can accept that as an answer if you insert as one Commented Sep 10, 2013 at 14:59

2 Answers 2

3

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:

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

This is beautiful. In 2025 replace: ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True, axisbg='#d5de9c') with: ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True) ax.set_facecolor("#d5de9c")
-1
import numpy as np
import matplotlib.pyplot as plt

def generate_satellite_plot(Az,El):
    fig = plt.figure()
    ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True)
    ax.set_theta_zero_location('N')
    ax.set_theta_direction(-1)
    ax.plot(np.deg2rad(Az),90-El,'*')
    ax.set_yticks(range(0, 90+10, 30))                   # Define the yticks
    yLabel = ['90', '60','30','0']
    ax.set_yticklabels(yLabel)
    ax.set_xticks(np.arange(0, np.pi*2, np.pi/2))                   # Define the xticks
    xLabel = ['N' , 'E','S','W']
    ax.set_xticklabels(xLabel)
    plt.show()


Az=[90, 180, 270]
El=[20, 30, 10]
Az= np.array(Az)
El= np.array(El)
generate_satellite_plot(Az,El)

The output of the code

1 Comment

Please add some explanations to your code so that it is useful for OP and anyone facing the same problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.