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:
...but I would like to set theta=0 to the 'West'. So something like:
Any ideas how to do this with matplotlib (I made the pic below in powerpoint) ?
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' .
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.
Simply use:
ax.set_theta_zero_location("W")
More info in the documentation of matplotlib.
A more flexible way:
ax.set_theta_offset(pi)
You can rotate the axis arbitrarily, just replace pi
with the angle you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With