Change the radius tick labels in a polar Matplotlib plot




Change radius tick labels

Luc B.



Polar Plot

Tick labels in Matplotlib polar plots often need to be adjusted so they aren't obstructed by lines. The interface to change polar tick labels is quite similar to that of standard Cartesian Matplotlib plots.

Note that you can also improve your polar plot by rotating tick labels into a different position.

Code Example

Use the plt.yticks() function to change the radius tick labels in a polar plot. The first argument is a list of tick mark positions, and the second optional argument is a list of textual tick labels.

import matplotlib.pyplot as plt
import numpy as np

theta = np.linspace(0, np.pi, 100)
r = np.sin(theta)

plt.polar(theta, r)

# Change tick labels here
plt.yticks([1, 2, 3, 4], ["a", "b", "c", "d"])


If the second label argument is omitted, plt.yticks() will default to use string representations of the tick positions.

More Examples

Object Oriented Interface

The same thing can be accomplished with Matplotlib's object oriented interface using the Axes.set_yticks() and Axes.set_yticklabels() functions.

# Create polar axes
ax = plt.axes(projection="polar")
ax.plot(theta, r)

# Change tick labels here
ax.set_yticks([1, 2, 3, 4])
ax.set_yticklabels(["a", "b", "c", "d"])