I want to align theta tick labels on a circle while also controlling start position and label order clockwise. Based on those two answers by ImportanceOfBeingErnest and Anmol Durgapal I was able to come up with this code, but that fails when I change the order and/or start with January north:
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure(figsize=(6, 6))
ax1 = fig.add_subplot(projection="polar")
labels = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
angles = [0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330]
theta_ticks = np.linspace(0.,330.,12)
plt.thetagrids(angles=angles, labels=labels)
for label, angle in zip(ax1.get_xticklabels(), theta_ticks):
x, y = label.get_position()
lab = ax1.text(x, y, label.get_text(), transform=label.get_transform(), ha=label.get_ha(), va=label.get_va())
lab.set_rotation(angle-90)
ax1.set_xticklabels([])
plt.show()
When I now add
ax1.set_theta_offset(np.pi / 2)
ax1.set_theta_direction(-1)
i get this: misaligned labels
Any ideas on how I can achieve this result?
This was achieved by editing the labels in reverse order and starting at April:
labels = ["April", "March", "February", "January", "December", "November", "October", "September", "August", "July", "June", "May"]
While that works it ruins the actual data I want to plot that relies on the theta_direction and offset.