0

I have been trying to plot a polar plot using matplotlib in python but has some problems. Instead of the normal 0-360 degrees, I want to put time,0-23hrs and radius will be in latitude degrees i.e from 90-0(pole to equator).

I have tried to change some settings in matplotlib projections polar.py example, but the result is not different. This is what I get:

polarplot

tmdavison
  • 64,360
  • 12
  • 187
  • 165
O. Adero
  • 9
  • 3
  • 1
    Welcome to StackOverflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). This will make it much easier for others to help you. – Jaap Mar 17 '16 at 13:12
  • What @Jaap said: Please show us the code you are using. This page might help also: [MCVE](//stackoverflow.com/help/mcve) – tmdavison Mar 17 '16 at 13:30

1 Answers1

1

If you are careful, you can consider inverting your latitudes and manually changing the tick labels on both axis.

Here's an example on how this can be achieved, more explanations as comments:

import numpy as np
from matplotlib import pyplot as plt

# set up random data between 0 and 90
r = [np.random.random() * 90.0 for i in range(0,10)]

# set up 24 hours matching the random data above
hours = np.linspace(0.0,24.0,len(r))
# scaling the 24 hours to the full circle, 2pi
theta = hours / 24.0 * (2.0 * np.pi)

# reverse your data, so that 90 becomes 0:
r_rev = [(ri - 90.0) * -1.0 for ri in r]

# set up your polar plot
ax = plt.subplot(111, projection='polar')
ax.plot(theta, r_rev, color='r', linewidth=3)

# define your axis limits
ax.set_ylim([0.0, 90.0])

# statically reverse your y-tick-labels
# caution: this turns your labels into strings
#          and decouples them from the data
# 
# the np.linspace gives you a distribution between 90 and 0 -
# the number of increments are related to the number of ticks
# however, you require one more label, because the center is 
#     omitted.  
ax.set_yticklabels(['{:.0f}'.format(ylabel) \
                for ylabel in np.linspace(90.0,0.0,len(ax.get_yticklabels())+1)[1:]])


# statically turn your x-tick-labels into fractions of 24
# caution: this turns your labels into strings
#          and decouples them from the data
#
# the number of ticks around the polar plot is used to derive
#    the appropriate increment for the 24 hours
ax.set_xticklabels(['{:.1f}'.format(xlabel) \
                    for xlabel in np.arange(0.0,24.0,(24.0 / len(ax.get_xticklabels())))])

ax.grid(True)

plt.show()

Your result will look like this (keeping in mind that the random data will be different):

new axis labels


to see that it actually works, you can replace the random r with this line:

r = np.linspace(0,90,10)

Now you know the r-values and can see how they are flipped.

Schorsch
  • 7,761
  • 6
  • 39
  • 65