Book Image

matplotlib Plotting Cookbook

By : Alexandre Devert
Book Image

matplotlib Plotting Cookbook

By: Alexandre Devert

Overview of this book

Table of Contents (15 chapters)
matplotlib Plotting Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using polar coordinates


Some phenomenon are of an angular nature. An example would be the power of a loudspeaker depending on the angle we measure it from. Polar coordinates are a natural choice to represent such data. Also, cyclic data such as annual or daily statistics can be conveniently plotted in polar coordinates. In this recipe, we are going to see how to work with polar coordinates.

How to do it...

Let's render a simple polar curve as follows:

import numpy as np
import matplotlib.pyplot as plt

T = np.linspace(0 , 2 * np.pi, 1024)
plt.axes(polar = True)
plt.plot(T, 1. + .25 * np.sin(16 * T), c= 'k')

plt.show()

The following figure shows a specialized layout for polar plots:

How it works...

As we have seen before, pyplot.axes() explicitly creates an Axes instance, which allows some custom settings. Simply using the optional polar parameter will set up a polar projection. Note how the legend adapts to the projection.

There's more...

Plotting curves is maybe the most common usage for polar...