Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate theta=0 on matplotlib polar plot

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

like image 737
HotDogCannon Avatar asked Nov 13 '14 10:11

HotDogCannon


People also ask

How do you rotate a polar plot?

Assuming you want to rotate by a multiple of 90 degrees, you can set the rotation of a polar plot by setting the ThetaZeroLocation , which sets where on the plot the zero angle is located. By default this is set to 'left' -- you can change this to one of 'left' , 'right' , 'bottom' , or 'top' .

How do I change the direction of Xticks in Python?

Rotate X-Axis Tick Labels in Matplotlib There are two ways to go about it - change it on the Figure-level using plt. xticks() or change it on an Axes-level by using tick. set_rotation() individually, or even by using ax.


Video Answer


2 Answers

Simply use:

ax.set_theta_zero_location("W")

More info in the documentation of matplotlib.

like image 140
hitzg Avatar answered Oct 20 '22 18:10

hitzg


A more flexible way:

ax.set_theta_offset(pi)

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

like image 17
Syrtis Major Avatar answered Oct 20 '22 18:10

Syrtis Major