Skip to content

MATLAB - Polar Plots

A polar plot visualizes data in a polar coordinate system, defined by a radius (rho) and an angle (theta), instead of the Cartesian (x, y) system. This representation is exceptionally useful for data with inherent directionality or periodicity.

Common Applications:

  • Engineering: Visualizing antenna radiation patterns or microphone pickup patterns.
  • Physics: Representing vector fields and orbital mechanics.
  • Data Science: Analyzing cyclical data, such as daily website traffic or monthly temperature variations.

MATLAB’s modern graphics system provides the polarplot function, a flexible and powerful tool for creating high-quality polar visualizations.

The primary function is polarplot(theta, rho), where theta is a vector of angles (in radians) and rho is a vector of corresponding radii.

Let’s plot a cardioid, given by the equation rho = 1 + cos(theta).

% Create a vector of angles from 0 to 2*pi
theta = linspace(0, 2*pi, 200);
% Calculate the corresponding radii
rho = 1 + cos(theta);
% Create the polar plot
figure;
polarplot(theta, rho);

This code generates a polar plot window. The resulting shape is a heart-like curve, known as a cardioid. It is symmetric about the horizontal axis, with its maximum radius of 2 at theta = 0 and its cusp (pinched point) at theta = pi where the radius is 0.

You can customize the line style, color, and markers using a LineSpec string, similar to the plot function. For more advanced control, use name-value pairs.

Let’s plot a four-leaf rose rho = sin(2*theta) with a thick, dashed red line and circle markers.

theta = linspace(0, 2*pi, 200);
rho = sin(2 * theta);
% Plot with LineSpec and name-value pairs
polarplot(theta, rho, '--ro', 'LineWidth', 2, 'MarkerFaceColor', 'y');

LineSpec Explanation:

  • '--': Dashed line
  • 'r': Red color
  • 'o': Circle markers

Name-Value Pairs:

  • 'LineWidth', 2: Sets the line thickness.
  • 'MarkerFaceColor', 'y': Fills the markers with yellow.

The output is a polar plot showing a flower-like shape with four ‘petals’ or lobes. The line is a thick, dashed red, with yellow-filled circles marking the points used to draw the curve.

You can plot multiple datasets on the same polar axes to compare them. This can be done in two main ways.

Provide multiple theta, rho, LineSpec triplets in a single call.

theta = linspace(0, 2*pi, 200);
rho1 = sin(2 * theta); % Four-leaf rose
rho2 = cos(2 * theta); % Another four-leaf rose, rotated
polarplot(theta, rho1, '-r', theta, rho2, '--b');

This generates a single plot with two overlapping shapes: a solid red four-leaf rose and a dashed blue four-leaf rose that is rotated by 45 degrees relative to the first.

The hold on command tells MATLAB to add subsequent plots to the current axes instead of replacing them. This is useful for building up complex plots programmatically.

theta = linspace(0, 2*pi, 200);
rho1 = sin(2*theta);
rho2 = 0.5 + zeros(size(theta)); % A circle with radius 0.5
polarplot(theta, rho1, 'LineWidth', 2); % Plot the first line
hold on;
polarplot(theta, rho2, '--k'); % Plot the second line on the same axes
hold off; % Best practice to release the hold

The result is a plot containing the blue four-leaf rose from the previous example, with a black dashed circle of radius 0.5 superimposed on it.

A good plot is a well-labeled plot. Use title, legend, and functions to adjust the axes limits and ticks.

theta = linspace(0, 2*pi, 100);
rho1 = 2*sin(3*theta);
rho2 = 2*cos(3*theta);
polarplot(theta, rho1, theta, rho2);
% Enhance the plot
title('Comparison of 3-Leaf Roses');
legend({'sin(3\theta)', 'cos(3\theta)'}, 'Location', 'bestoutside');
% Get the polar axes object to customize it
pax = gca;
pax.ThetaZeroLocation = 'top'; % Set 0 degrees to be at the top
pax.ThetaDir = 'clockwise'; % Make angles increase clockwise
pax.Rlim = [0 2.5]; % Set radius limits

This code creates a highly customized plot showing two three-leaf roses. A title and legend clearly explain the content. The axes are modified so that the 0-degree angle is at the top (like a compass), angles increase clockwise, and the radial axis extends to 2.5, providing some space around the curves.

Mini-Project: Visualizing an Antenna Pattern

Section titled “Mini-Project: Visualizing an Antenna Pattern”

Goal: Plot the radiation pattern of a simple half-wave dipole antenna. The normalized power intensity is given by rho = (cos(pi/2 * cos(theta)) / sin(theta))^2.

% Use a small epsilon to avoid division by zero at theta=0 and pi
eps = 0.001;
theta = linspace(eps, 2*pi-eps, 200);
% Antenna pattern formula
rho = (cos(pi/2 * cos(theta)) ./ sin(theta)).^2;
polarplot(theta, rho);
title('Half-Wave Dipole Antenna Radiation Pattern');
% Set radial limits to focus on the main lobes
pax = gca;
pax.RLim = [0 1];

This project connects the polarplot function to a real-world electrical engineering application, showing how it’s used to understand where an antenna transmits its power most effectively (the two large lobes at theta = pi/2 and theta = 3pi/2).