Code covered by the BSD License  

Highlights from
3D Polar Plot

4.875

4.9 | 8 ratings Rate this file 116 Downloads (last 30 days) File Size: 250.73 KB File ID: #13200
image thumbnail

3D Polar Plot

by Ken Garrard

 

01 Dec 2006 (Updated 12 Oct 2011)

Plots 3d polar data with polar axis and polar grid

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information
Description

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.

Example
The 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);
   figure('color','white');
   polarplot3d(P,'colordata',gradient(P));
   view([-18 72]);

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

Versions
1 Original function based on POLAR3D by J De Freitas
2 Changed argument method to 'property',value pairs using PARSE_PV_PAIRS
2.1 Added 'ColorData' property
2.2 Updated contour plot implementation
2.3 Added radial and azimuthal mesh scale factors
2.4 Added 'CartOrigin' property
2.5 Added 'PolarAxisColor', 'GridColor', 'TickColor' and 'TickLabelColor' properties
2.6 Added 'PolarDirection' and 'GridScale' properties
3 Removed PARSE_PV_PAIRS dependency
4 Support for non-uniform grid spacing. Removed redundant 'MeshL' plot type

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
3D Polar Plot

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (17)
02 Dec 2006 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.

03 Dec 2006 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.

20 May 2007 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?

21 May 2007 Ken Garrard

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

05 Apr 2010 Bin Liang

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

28 Apr 2010 Virendra  
09 Sep 2010 Jérika

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

15 Feb 2011 Camille Couzi

Hi,
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!
Camille.

19 Mar 2011 Qun HAN

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

15 Sep 2011 dimaro

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

16 Sep 2011 Daniel

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

http://www.kemt.fei.tuke.sk/predmety/KEMT515_MT/_materialy/signal/signal/private/parse_pv_pairs.m

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

31 Oct 2011 Ahmed Hassaan  
13 Dec 2011 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?

14 Dec 2011 Anson Ting  
25 Dec 2011 Ken Garrard

Jim,
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
   set(gca,'visible','on');
after plotting your data with polarplot3d.

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

08 Feb 2012 dd

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?

09 Feb 2012 Ken Garrard

dd,
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'.

Please login to add a comment or rating.
Updates
06 Dec 2006

Changed input arguments to list of 'property',value pairs.

29 Oct 2007

Added surface coloring property.

12 Oct 2011

This update supports non-uniform spacing of the rows and columns of the input data matrix, allows more control over the polar grid overlay and removes the dependency on PARSE_PV_PAIRS.

Tag Activity for this File
Tag Applied By Date/Time
specialized Ken Garrard 22 Oct 2008 08:51:00
plotting Ken Garrard 22 Oct 2008 08:51:00
polar Ken Garrard 22 Oct 2008 08:51:00
plot Ken Garrard 22 Oct 2008 08:51:00
3d Ken Garrard 22 Oct 2008 08:51:00
graphics Ken Garrard 22 Oct 2008 08:51:00
polar Lew 03 Oct 2011 10:44:12
pick of the week Lindsay Coutinho 11 Nov 2011 11:13:19
potw Lindsay Coutinho 11 Nov 2011 11:13:19
polar yves 16 May 2012 09:42:25

Contact us at files@mathworks.com