Skip to content
Tutorials Center
My learning

Topics

Lesson 35 of 57 ยท 3D, Animation and Advanced

Polar Plots and Radar Charts

Use projection=polar for angle and radius data: rose and wind charts, polar bars, circular histograms, log radius and a radar chart built from polar axes.

Some data is naturally circular: wind direction, hours of the day, compass bearings, repeating cycles, or a profile with several scores arranged around a wheel. Cartesian axes tear these data apart at the edges (is 359 degrees far from 1 degree?). Polar axes keep them together: a point is described by an angle and a distance from the centre.

In this lesson you will make a polar Axes, learn the direction and zero-location settings, draw bars and histograms around the circle, build a radar chart from scratch, and see the pitfalls of radial scales. It builds on bar charts and histograms.

A polar Axes: theta and r

Pass projection="polar" and Matplotlib creates an Axes whose x values are the angle theta in radians and whose y values are the radius r. This is the single most common mistake: if you give degrees, you will draw a wild spiral. Convert with np.deg2rad.

Python
fig, ax = plt.subplots(subplot_kw={"projection": "polar"})
ax.plot(theta, r)

Four settings control the layout:

  • ax.set_theta_zero_location("N") puts 0 at the top ("N" for north). The default is east (right).
  • ax.set_theta_direction(-1) makes angles increase clockwise, like a compass. The default is counter-clockwise.
  • ax.set_rlabel_position(angle) moves the radius labels so they do not hide the data.
  • ax.set_rlim(0, 10) and ax.set_rticks([...]) set the radius range and ticks.

Reading a polar plot

theta The angle, in radians.
r Distance from the centre.
Zero and direction Set N and clockwise for compass data.

Radians in, always. Use np.deg2rad for degrees.

1 / 2
Python Curves, spirals and a rose

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

fill closes the curve and shades the inside. Everything you know about plot (colour, line style, labels, legends) still applies.

Polar bars and wind roses

ax.bar(theta, height, width=...) draws wedges: theta is the centre angle of each wedge, width its angular size (in radians) and height the radius. Eight bars of width 2*pi/8 make a compass rose. Add bottom to leave a hole in the middle (a donut-style rose) and stack several bar calls to show wind speed bands.

Python A compass wind rose with stacked speed bands

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice the order: we set zero to north and clockwise before labelling the ticks, so "N" really is up. For directional data this is almost always what readers expect.

Circular histograms

Angles wrap around, so a histogram of times of day or bearings should be circular too. Compute the counts with np.histogram using bin edges that cover 0 to 2*pi, then draw the counts as polar bars. A plain Cartesian histogram would split a cluster that straddles midnight into two pieces at the edges.

Python
counts, edges = np.histogram(angles, bins=24, range=(0, 2 * np.pi))
ax.bar(edges[:-1], counts, width=np.diff(edges), align="edge")

One caveat: in a polar bar chart the area of a wedge grows with the square of the radius, so large counts look exaggerated. A common fix is to plot the square root of the counts so that area is proportional to the count, or at least to say so.

Radar charts from polar axes

A radar (spider) chart shows several scores per item, each on its own spoke. Matplotlib has no built-in radar chart, but it is a short recipe: place one angle per category, repeat the first value at the end to close the polygon, and use fill for the shaded area.

Python A radar chart comparing two profiles

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

set_theta_offset(np.pi / 2) rotates the zero position, which is the other way (besides set_theta_zero_location) to start at the top.

Radar charts are popular but easy to misuse. The shape you see depends on the order of the spokes, and the area is not a meaningful total. Only use them with a small number of categories that share one scale, and consider a plain bar chart when readers need exact comparisons.

Log radius and other scales

ax.set_rscale("log") gives a logarithmic radius, which helps when values span several orders of magnitude (signal strength, antenna patterns in decibels). The centre can no longer be zero, so use ax.set_rlim(0.1, 1000). The related set_rorigin lets you shift where the centre sits so the plot becomes a ring. Bars in a log-polar plot start at the origin, so use them with care; lines and markers are usually clearer.

Matplotlib can also draw map projections ("mollweide", "hammer", "aitoff", "lambert"), which take longitude and latitude in radians. They are useful for sky or globe sketches; real geographic maps with coastlines usually need an add-on library, covered in The Matplotlib Ecosystem.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In a polar Axes, which unit does the angle (theta) use?

    Polar Axes take theta in radians. Convert degrees with np.deg2rad, or the plot will wrap around many times.
  2. 2. How do you make angles start at the top and increase clockwise, like a compass?

    set_theta_zero_location chooses where zero sits, and set_theta_direction(-1) reverses the direction to clockwise.
  3. 3. Why does a radar chart need the first value repeated at the end of each series?

    plot and fill draw straight segments between listed points. Repeating the first angle and value joins the last point to the first.
  4. 4. What is a weakness of the polar bar chart as a histogram?

    Because a wedge is wider farther from the centre, the visual area exaggerates large counts. Plotting the square root of the counts is one fix.

Summary

  • projection="polar" makes an Axes where x is the angle in radians and y is the radius.
  • set_theta_zero_location, set_theta_direction, set_theta_offset, set_rlim, set_rticks and set_rlabel_position control the layout.
  • ax.bar gives wind roses and circular histograms; stack bars with bottom.
  • A radar chart is a polar plot plus fill with the first point repeated; keep it to few, comparable categories.
  • set_rscale("log") handles wide value ranges; mind the wedge-area distortion in polar bars.

Next, make figures move in Animation Concepts.