Rotate theta=0 on matplotlib polar plot

Question:

I have the following example code:

import numpy as np
import matplotlib.pyplot as plt
import random

data_theta = range(10,171,10)

data_theta_rad = []
for i in data_theta:
    data_theta_rad.append(float(i)*np.pi/180.0)

data_r = random.sample(range(70, 90), 17)

print data_theta
print data_r

ax = plt.subplot(111, polar=True)
ax.plot(data_theta_rad, data_r, color='r', linewidth=3)
ax.set_rmax(95)
# ax.set_rmin(70.0)
ax.grid(True)

ax.set_title("Example", va='bottom')
plt.show()

…which produces something like this:
enter image description here

…but I would like to set theta=0 to the ‘West’. So something like:

enter image description here

Any ideas how to do this with matplotlib (I made the pic below in powerpoint) ?

Asked By: HotDogCannon

||

Answers:

Simply use:

ax.set_theta_zero_location("W")

More info in the documentation of matplotlib.

Answered By: hitzg

A more flexible way:

ax.set_theta_offset(pi)

You can rotate the axis arbitrarily, just replace pi with the angle you want.

Answered By: Syrtis Major
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.