Polar Axes Appearance and Behavior in MATLAB
Polar axes are coordinate axes where the two coordinate axes are r-axis for magnitude and theta-axis for angles. MATLAB has many functions to change the properties of these polar axes which we shall see throughout this article. In this article we shall see how to modify following properties of polar axes in MATLAB:
- Axes limits
- Axes ticks
- Axes tick labels
- R-axis tick angle
Let us see each of these with an example each.
Axes Limits:
MATLAB provides us with options to change the limits of r and theta axis by using the rlim() and thetalim() functions.
Syntax:
rlim(<limits of r-axis>)
thetalim(<limits of theta-axis>)
We can pass a certain range for the limits of r-axis and theta-axis and the above functions will change the visible range of the polar axes. We will plot a sin curve in polar axes with theta ranging from 0 to 270 degrees and r ranging from 0 to 1.5.
Example 1:
Matlab
% MATLAB code for % Defining polar axes ax=polaraxes; % Defining x data r=linspace(-pi,pi); % Plotting sin(r) in axes ax plot(ax,r,sin(r)) % Setting r-limits to 0->1.5 rlim([0 1.5]) %Setting theta-limits to 0->270 degrees thetalim([0 270]) |
Output:
Axes Ticks:
We can change where the ticks are marked on r and theta axes using the following functions.
Syntax:
rticks(<vector with tick values>)
thetaticks(<vectors with tick values in degrees>)
See the following example for understanding the above functions.
Example 2:
Matlab
% MATLAB code for axes ticks ax=polaraxes; r=linspace(-pi,pi); plot(ax,r,sin(r)) % Giving tick values rticks([0 .23 .5 1 ]) thetaticks([0 23 31 180 203 211]) |
Output:
Axes tick Labels:
Just as we changed the tick values in the above example, we can change the labels given to those ticks as well using the following functions.
Syntax:
rticklabels(<labels>)
thetaticklabels(<labels>)
We will now plot the trigonometric identity sin2(r) + cos2(r) = 1, in polar frames with only the 4 directions on the theta axis.
Example 3:
Matlab
% MATLAB code for Axes tick Labels ax=polaraxes; r=linspace(-pi,pi); % Plotting the identity plot(ax,r,sin(r).^2+cos(r).^2) rticks([0 .23 .5 1 ]) % Setting r tick labels rticklabels([ "a=0" , "b=.23" , "c=.5" , "d=1" ]) thetaticks([0 90 180 270]) % Setting theta tick labels thetaticklabels([ "East" , "North" , "West" , "South" ]) |
Output:
R-Axis Tick Angles:
We can change the orientation of r-tick labels in which they are displayed. There is a simple function for the same.
Syntax:
rtickangle(<angle of rotation>)
We can use the above function without an argument to query the current r-tick angle. Getting the current rotation angle. Consider the following plot.
We can query its rtickangle like following.
Example 4:
Matlab
% MATLAB code ax=polaraxes; r=linspace(-pi,pi); plot(ax,r,sin(r).^2+cos(r).^2) % Getting the rtickvalue ang=rtickangle |
Output:
As we can see, the default angle of r-ticks is 0 degrees.
Example 5:
Matlab
% Changing the r-tick angle in MATLAB ax=polaraxes; r=linspace(-pi,pi); plot(ax,r,sin(r).^2+cos(r).^2) % Rotating rtick labels to 310 degree rtickangle(ax,310) |
Output: