Plot using polar coordinates in Matplotlib

Python

Matplotlib

Polar

Create

Luc B.

Python

Matplotlib

Polar Plot

Unlike the standard Cartesian coordinates, polar coordinates specify the location of points using an angle and a distance from the origin. Polar coordinates have a wide array of applications in mathematics, science, and engineering.

Code Example

Use the plt.polar() function to create a polar plot in Matplotlib.

import matplotlib.pyplot as plt
import numpy as np

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

# Create polar plot here
plt.polar(theta, r)

plt.show()

png

More Examples

Object Oriented Interface

The same thing can be accomplished with Matplotlib's object oriented interface by creating axes using the polar projection.

# Create polar axes
ax = plt.axes(projection="polar")

# Create polar plot here
ax.plot(theta, r)

plt.show()

png