tags:

views:

4740

answers:

3

I'm using polar plots (POLAR(THETA,RHO)) in MATLAB.

Is there an easy way to fix the range for the radial axis to say, 1.5?

I'm looking for something analogous to the xlim, ylim commands for cartesian axes. Haven't found anything in the docs yet.

Thanks in advance.

+3  A: 

Here's how I was able to do it.

The MATLAB polar plot (if you look at the Handle Graphics options available) does not have anything like xlim or ylim. However, I realized that the first thing plotted sets the range, so I was able to plot a function with radius range [-.5 .5] on a [-1 1] plot as follows:

theta  = linspace(0,2*pi,100);
r      = sin(2*theta) .* cos(2*theta);
r_max  = 1;
h_fake = polar(theta,r_max*ones(size(theta)));
hold on;
h      = polar(theta, r);
set(h_fake, 'Visible', 'Off');

That doesn't look very good and hopefully there's a better way to do it, but it works.

Tim Whitcomb
That's clever. Thanks.I'm surprised they don't provide a more direct control over radius.
Adam
Me too - I wouldn't think that wanting to tweak the radius would be *that* rare
Tim Whitcomb
I've come up with the same solution. Unfortunately, they don't define a polar plot as a base graph type, instead creating patches to draw the axes and transforming your data into x and y. Take a look at the code for polar.m sometime and you'll see.
Scottie T
As Scottie T mentions above, a polar plot is actually just a bunch of patch, line, and text objects drawn on an invisible Cartesian graph. You can take a peek at all the little graphics objects that form the polar plot by "unhiding" their handles with the following: >> kids = get(gca,'Children') % Display the current axes children >> set(0,'ShowHiddenHandles','on'); >> hiddenKids = get(gca,'Children') % Display the hidden children too
gnovice
A: 

this worked for me... i wanted the radius range to go to 30, so i first plotted this

polar(0,30,'-k')
hold on

and then plotted what i was actually interested in. this first plotted point is hidden behind the grid marks. just make sure to include

hold off

after your final plotting command.

+1  A: 

In case anyone else comes across this, here's the solution:

As Scottie T and gnovice pointed out, Matlab basically uses the polar function as an interface for standard plots, but with alot of formatting behind the scenes to make it look polar. Look at the values of the XLim and YLim properties of a polar plot and you'll notice that they are literally the x and y limits of your plot in Cartesian coordinates. So, to set a radius limit, use xlim and ylim, or axis, and be smart about the values you set:

rlim = 10;
axis([-1 1 -1 1]*rlim);

...that's all there is to it. Happy Matlabbing :)

CalPolyAero

related questions