Home > Software design >  Matplotlib Polar Plot - Overriding major tic axis labels
Matplotlib Polar Plot - Overriding major tic axis labels

Time:08-18

Using a list with 360 entries, I am creating a polar chart with MatplotLib. This works nicely:

%matplotlib widget

fig = plt.figure()
ax = fig.add_subplot(projection='polar')
for rad in np.arange(0, (2 * np.pi), 2 * np.pi / 360):
    plt.polar(rad, random.random()*10, marker='.', markersize=2, color='green')
plt.show()

But I get degrees 0 through 360, with 0 at "3pm". What I want is to have labels at 3, 6, 9 and 12 be, respectively, Front, Right, Back and Left. And then I want to rotate the whole thing so that Front as at 12.

CodePudding user response:

You could use ax.set_theta_zero_location with whatever direction you want (East,West,South,North) to change the location of the origin 0. See doc enter image description here

EDIT:

To change the ticks to "Front",etc, you can use: ax.set_xticklabels(['Front','','Left','','Back','','Right'])

See output below:

enter image description here

  • Related