Adjust the radius limits in Matplotlib polar plot

Python

Matplotlib

Polar

Adjust radius limits

Luc B.

Python

Matplotlib

Polar Plot

While Matplotlib automatically picks radius limits for polar plots, it's sometimes necessary to tweak them manually to suit a particular visualization.

Code Example

Use the plt.ylim() function to adjust the radius limits in Matplotlib.

import matplotlib.pyplot as plt
import numpy as np

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

# Adjust radius limits here
plt.ylim((0, 5))

plt.show()

png

More Examples

Object Oriented Interface

The same thing can be accomplished with Matplotlib's object oriented using the Axes.set_rlim() function. Note that Axes.set_rlim() is a wrapper for Axes.set_ylim(), so either function will work.

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

# Adjust radius limits here
ax.set_rlim((0, 5))

plt.show()

png