File Exchange

image thumbnail

3D Polar Plot

version (431 KB) by Ken Garrard
Plots 3d polar data with polar axis and polar grid


Updated 04 Mar 2016

View Version History

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

Polarplot3d produces surface, mesh, wireframe and contour plots for three dimensional polar data. A labeled polar axis is drawn at a fixed height or it can follow the surface contour at maximum radius. A polar grid can also be drawn on top of the surface.
This function is based on polar3d by J De Freitas, file exchange ID 7656.
The input parameters are a matrix of magnitudes, Zp, and a list of property,value pairs that modify the default plot behavior. Each column of Zp contains information along a single half-meridian and each row gives height values along a circular arc. By default Zp is assumed to be increasing in radius down each column and increasing in angle (counter-clockwise) along each row. The default plot is drawn over a full circle of unit radius.
'RadialRange' and 'AngularRange' properties can be used to specify the upper and lower angular and radial values over which the data is plotted. The relative ordering of the angular and radial range vectors is used to determine the angular and radial direction sense of the rows and columns of Zp. Alternatively a vector can be specified giving the locations of each row or column.

The polar axis can be placed at the minimum, maximum or mean value of Zp at the largest radius, at the top or bottom of the plot box, at a user specified location, or it can follow the surface at the perimeter of the data. The polar axis tick mark spacing can be adjusted with the 'TickSpacing' property.

The default polar axis orientation is that zero degrees is along the +X axis and increasing angles are counter-clockwise. The 'PolarDirection' property can be used to change this to a compass style plot with zero degrees along the +Y axis and increasing angles going clockwise around the pole.

Default surface coloring is according to the values in Zp. This can be changed by supplying a matrix the same size as Zp as the value of the 'ColorData' property.

A scaling parameter can be specified to interpolate the data onto a finer or coarser mesh. The output Cartesian data is returned in three matrices.

The example plot in the screenshot was produced with the following commands.

[t,r] = meshgrid(linspace(0,2*pi,361),linspace(-4,4,101));
[x,y] = pol2cart(t,r);
P = peaks(x,y); % peaks function on a polar grid

% draw 3d polar plot
figure('Color','white','NumberTitle','off','Name','PolarPlot3d v4.3');
polarplot3d(P,'PlotType','surfn','PolarGrid',{4 24},'TickSpacing',8,...
'AngularRange',[30 270]*pi/180,'RadialRange',[.8 4],...
'RadLabels',3,'RadLabelLocation',{180 'max'},'RadLabelColor','red');

% set plot attributes
set(gca,'DataAspectRatio',[1 1 10],'View',[-12,38],...
'Xlim',[-4.5 4.5],'Xtick',[-4 -2 0 2 4],...
'Ylim',[-4.5 4.5],'Ytick',[-4 -2 0 2 4]);
title('polarplot3d example');

The zip file contains the polarplot3d function and an m-file with example plots.

Cite As

Ken Garrard (2021). 3D Polar Plot (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (58)

飞 肖

Woongji Kim

Taru Laitinen

Vasile Tanasa

Sanchit Uke

Jani Maenpaa

Matrix import from xls is considered as non-numeric by polarplot3d
e.g. matrix = readtable('<filename>','Sheet','Sheet1');
and conversion to numeric
Zp= table2array(matrix);

Should work after that

Michael Crosley

Vishal Jain

Ive imported a 19x25 matrix from excel which I want to plot and have inputted that as Zp but I keep getting the error, Color matrix must be numeric and the same size as Zp, how do I fix this?


very beautiful! Has imaged such figures for a long time ! Thank you very much.

Simone Pardini

Xutao Chen

Julien LoTufo

Is there any way to make the entire surface one color? I'm using this function as an overlay to cover some empty values.

Dan Midgett

Great function. I do find it a bit odd that the sectors of data are drawn assuming the sector is clockwise from the given theta value. In many applications (such as data from radial sector scans) the drawn sector should be centered on the given theta value not to the side of it. Anyway, this is easy enough to fix by giving your theta data an offset of half a sector in radians, but I thought I would mention it. Might be good to add as a new option.

Jeff Severino

Jingwei Zhuang

Len Lattanzi

Thorsten Schultz

Poul Hoang

Gina Collecchia

Can you give an example that doesn't use the peaks function, e.g., a trigonometric example like drawing a sphere?


I figured it out how to use it with imported data after reviewing the script more closely. Simply import data as a two dimensional matrix and use it in the polarplot3d function. Works great!


Hi Ken, this is spectacular. How would you adjust the command if you're using imported data. For instance, I have an absorption spectra every 5 degrees in rotation (i.e., from 0 to 355 degrees) for a given sample.

Xiaodong Wang

Stuart Anderson

Extremely useful script. Having so many examples included enabled me to understand the consequences of parameter choice immediately. Well done Ken !


Habib Dogan


I have three matrices

z=[11X8] matrice

z have some value(dBm)

can I use this polarplot3d function

I want to show z values in any degree and in any radius..




Please, include the visualisation of the mean gradient of the figure. For instance, heart has a mean electrical gradient. It would be very useful to have it. For instance, here its Math

Iuri Andrade

Awesome script!
Thanks a lot.
Is it possible to put a label to the z axis?


hello ken,
thank you for the excellent code here
i have a problem, i m trying to represent my data in 3D polar plot.
the radius is constant for all values 5
theta= [ 30 60 75 90] and the z for each theta are [0.35 0.5 0.6 0.75]. so the peaks must represent the z values.

thank u in advance


Hi Ken,

Thank you for all the excellent work here!!!!

I have a question. In the following 14 by 16 data matrix:

Data_Right_Arm= [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0.8 1 1 0
0 0 0 0 0 0 0 0.5 0 0 0 0 0.9 1 1 0
0.95 0.5 0.5 0 0.5 1 1 0.95 0 0 0 0 0.6 1 1 1
1 0.95 0.9 1 0.95 0.95 0.9 1 0 0 0 0 0.6 1 1 1
1 1 1 1 0.7 0.95 0.8 0.8 0 0 0 0 0.5 1 0.95 0.95
0.9 0.8 0.85 0.8 0.4 1 1 0.95 0 0 0 0 0.55 1 1 1
1 1 0.85 0.85 0.85 0.8 0.9 0.85 0 0 0 0 0.55 1 0.95 1
1 0.85 0.95 1 0.8 0.95 0.95 0.95 0 0 0 0 0.55 0.95 1 1
0.9 0.8 1 1 0.5 1 0.95 1 0 0 0 0 0.75 1 0.95 0.95
0.85 0.95 0.85 1 0.8 0.95 0.9 0.95 0 0 0 0 0 1 1 0.75
0.9 0.9 1 1 0.7 1 0.9 0.8 0 0 0 0 0 0 0 0.75];

which for each column there is an angle correspondence as follows:

angles_deg=[0 22.5 45 67.5 90 112.5 135 157.5 180 202.5 225 247.5 270 292.5 315 337.5]

I need to create a 3D polar plot grid with the cells containing colours that represent the values of my data matrix from 0 to 1. I tried to use the "polarplot3d" function as follows:

t2 = [11.25 371.25]*pi/180;
r2 = [0 1.5];

%% Plot using default arguments
'polargrid',{15 16},'tickspacing',22.5, 'GridScale', [100 100], 'angularrange',t2 );
view([-18 76]);

But I haven't managed to get the right results. Any suggestions would be greatly appreciate it.




Ken Garrard

You could try using the return matrices Xi,Yi,Zi to make an interpolating function. Then find z values corresponding to any x,y points you want.

An example, using scatteredInterpolant,

[t,r] = meshgrid(linspace(0,2*pi,361), ...
[x,y] = pol2cart(t,r);
P = peaks(x,y);
angR = [20 350]*pi/180;
radR = [.8 4];
[xi,yi,zi] = ...
polarplot3d(P, ...
'AngularRange',angR, ...
zFun = ...
scatteredInterpolant(xi(:),yi(:),zi(:), ...


Excellent script; thank you very much for it.

I would like to interpolate across the center of the plot(constituted by the first row or the input vector), as well as between the first and last column of the input vector.

Could you advise me on how to proceed with this?

Ken Garrard

I believe this is due to an opengl bug. For example,
polarplot3d(peaks(101),'cartorigin',[10^6 10^8]);
is mangled. But,
polarplot3d(peaks(101),'cartorigin',[10^6 10^8]);
looks good. Painters works too but the gridlines aren't drawn very well.

Seb Biass

Reall good script that does pretty much everything I needed. However, when trying to shift the CartOrigin to projected UTM coordinates (i.e. 10^5 on x and 10^6 on y), the mesh is totally disturbed. Any idea where that occurs?


Great work !
This code is very helpful for a work about nanoparticles diffusion inside a human cell... Probably not what you thought when creating this code

Daniel Zanotta

Very good! Well writen and easy to use.

Edward Liao

Good job!
I wonder how to deal with this case, if the distribution of data points is not uniform, for example, data points are more dense with the increase of radial distance, so we use a cell rather than a matrix to store data.

Edward Liao

Good job!
I wonder how to deal with this case, if the distribution of data points is not uniform, for example, data points are more dense along radial directions.


How to download


Ken Garrard

Line 589 uses a ~ (tilde) character as a placeholder for an unneeded function return value. You must be using a version of Matlab prior to the introduction of this feature. Replace the ~ with an unused variable name such as 'dontcare'.


Hi Ken,
I get the following error msg when running the demo code:

??? Error: File: polarplot3d.m Line: 589 Column: 3
Expression or statement is incorrect--possibly unbalanced (, {, or [.

Can you help me on this?

Ken Garrard

The contour function adds Cartesian axes to the figure. I set the 'visible' property of those axes to 'off' in polarplot3d. To turn them on type
after plotting your data with polarplot3d.

If you want only axis labels and a plot title enter
set(get(gca,'title'), 'visible','on);

Anson Ting

Jim Teunas

This is very usefull.,,,BUT I have problems with 'contour'....when I run the example with 'surfn' canged to 'contour' all the formating, axis lables, title everything disapears!....what is wrong....could someone send me an example of how to use the contour option?

Ahmed Hassaan


@dimaro - I found a version of "parse_pv_pairs.m" here:

With that said, I haven't had a chance to try the script (i.e., 3D Polar plot), so I don't know if it will work


I don't find the parse_pv_pairs function?Can somebody help me?


This is really a good work. Save me a lot of time. Thanks.

Camille Couzi

I am working with geographic data, so my zero direction (north) is up, and the degrees increase in the way of a clock (so at the inverse as your script).
How can I modify your program in order to be able to use it?
Thanks in advance!


Got nice plots. Exactly what I needed for pole figures. Thanks!


Bin Liang

Awesome work!! I helps me a lot! Thanks!

Ken Garrard

You need to download the function parse_pv_pairs (FEX Id 9082). Polarplot3d uses it to process optional input arguments.

Dinesh Bansal

( am using Matlab b) version and I am not able to run this funciton (even for the example given in the code). I get the following error:??? Error using ==> polarplot3d
Error parsing varargin list
??? Undefined function or method 'parse_pv_pairs' for input arguments of type 'struct'.
Can anyone tell me how to circumvent this problem?

Ken Garrard

submission update

Thanks for you comments John. I too prefer 'property',value pairs when the argument list is long and have updated my submission to use parse_pv_pairs. Just think what the handle graphics functions would be like without varargin and p,v pairs.

John D'Errico

Good documentation, many examples, full of features.

If I look for something to gripe about, I prefer the use of property/value pairs for a code with many optional arguments, most of which will take on their default values.

MATLAB Release Compatibility
Created with R2016a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!