How to make a polar plot with Matplotlib using Python

7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

Polar plots are really useful when you need to show something on a rotating axis.

Especially when your are working with geometry problems or when displaying world maps.

Let me show you

Here is an example of a simple line on a simple 2d axis.

# To generate data
import numpy as np

# To plot it
import matplotlib.pyplot as plt

# We generate our sample data
theta = np.arange(0,3,.01) * np.pi
rho = np.sin(4*theta)*np.cos(4*theta)

# We create our canvas
fig, axes = plt.subplots(1,
                         1,
                         figsize=(8,6))

# We plot a line plot on a polar axis
axes.plot(theta, rho)

# We change the number of half
axes.grid(True)

axes.set_title("A simple line plot")
plt.show()
A normal line plot
The simple line plot

Here is how to plot it on a polar axis

# To generate data
import numpy as np

# To plot it
import matplotlib.pyplot as plt

# We generate our sample data
theta = np.arange(0,3,.01) * np.pi
rho = np.sin(4*theta)*np.cos(4*theta)

# We create our canvas
fig, axes = plt.subplots(1,
                         1,
                         figsize=(8,8),
                         # We specify here the type of projection we want
                         subplot_kw={'projection': 'polar'})

# We plot a line plot on a polar axis
axes.plot(theta, rho)

# We change the number of half
axes.grid(True)

axes.set_title("A line plot on a polar axis")
fig.tight_layout()
plt.show()

As you can see using the subplots_kw={'projection': 'polar'} it is pretty simple to go from a simple line plot to a polar projection.

A line plot on a polar axis

Here you are, as you can see we projected the same simple line but on a polar axis.

More on Matplotlib

If you like what you've just read and want to know more about the Matplotlib library (e.g. how to add labels, plot different types of plots, etc...) check out the other articles I wrote on the topic, just here :

Matplotlib - The Python You Need
We gathered the only Python essentials that you will probably ever need.
7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

Free Newsletter

Master Data Science in Days, Not Months 🚀

Skip the theoretical rabbit holes. Get practical data science skills delivered in bite-sized lessons – Approach used by real data scientist. Not bookworms. 📚

Weekly simple and practical lessons
Access to ready to use code examples
Skip the math, focus on results
Learn while drinking your coffee

By subscribing, you agree to receive our newsletter. You can unsubscribe at any time.