## How do I create a contour plot in polar coordinates?

### MathWorks Support Team (view profile)

on 27 Jun 2009
Latest activity Edited by MathWorks Support Team

### MathWorks Support Team (view profile)

on 26 Sep 2018
Accepted Answer by MathWorks Support Team

### MathWorks Support Team (view profile)

I would like to create a contour plot on polar axes similar to the plots produced by the POLAR function. My data set is defined in (R, theta) coordinates.

R2006a

### MathWorks Support Team (view profile)

on 27 Jun 2009

A function that creates a polar contour plot is not present in MATLAB.
True polar axes are not supported in MATLAB. The POLAR function does the following to create a plot:
1. Accepts polar coordinates
2. Converts the data to Cartesian coordinates and plots them.
3. Draws the polar grid lines and text on a Cartesian axes system.
To create a contour plot in polar coordinates, you will need to follow a similar procedure. The following code shows an example:
% Create polar data
[r,t] = meshgrid(0:.1:5,0:pi/30:(2*pi));
z = r - t;
% Convert to Cartesian
x = r.*cos(t);
y = r.*sin(t);
Next, you can produce the annotations using the POLAR function and create the contour plot:
h = polar(x,y);
hold on;
contourf(x,y,z);
% Hide the POLAR function data and leave annotations
set(h,'Visible','off')
% Turn off axes and set square aspect ratio
axis off
axis image
Some of the annotations may be obscured when the contour plot is drawn. The most reliable way to work around this issue is to manually redraw them using the Plot Tools GUI or the ANNOTATION function.

Oliver

### Oliver (view profile)

on 4 Mar 2015
Hi there,
I tried to do this but that did not work
code:
[r,t] = meshgrid(0:.1:5,0:pi/30:(2*pi));
z = r - t;
% Convert to Cartesian
x = r.*cos(t);
y = r.*sin(t);
h = polar(x,y);
hold on;
contourf(dist);
% Hide the POLAR function data and leave annotations
set(h,'Visible','off')
% Turn off axes and set square aspect ratio
axis off
axis image
where dist = 21x144 array. I want it to form a ring donut shape aroud the middle the upper data starting at r = 20 and the lower limit at r = 21. And the 144 being each th step
Mike Garrity

### Mike Garrity (view profile)

on 4 Mar 2015
You need to pass the x & y arrays into the contourf function. If you don't, it will just use the defaults which go along the X & Y axes.
David C

### David C (view profile)

on 5 Jun 2015
"Some of the annotations may be obscured when the contour plot is drawn." Does this mean the annotations in the procedure described above may produce incorrect annotations?