Why is the TITLE of my polar plot obscured when I rotate the plot using VIEW in MATLAB 7.11 (R2010b)?

10 views (last 30 days)
I noticed that the title for a plot is obscured when rotating a polar plot 90 degrees. I do this to present data in a compass orientation (0 degrees up). I would like a simple workaround for the plot changing size when the view is rotated.
Refer to the following code:
function polarViewLayoutIssue()
% The title fits in this plot nicely (default view).
hAxes = drawPolar();
view(hAxes, [0 -90]);
% Why does the polar plot expand to obscure the title when rotated?
hAxes = drawPolar();
view(hAxes, [90 -90]);
end
function hAxes = drawPolar()
hFig = figure();
hAxes = axes('Parent', hFig);
polar([0 pi/2 pi 3*pi/3], [1 2 3 4])
title('Title for this figure')
end

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Jan 2011
This polar plot behavior is an artifact of MATLAB’s plotting method. The polar coordinates are converted to Cartesian coordinates before being plotted, which causes the size of the rotated plot to shift depending on the aspect ratio of the figure.
To work around this issue, it is necessary to manually set the title’s position by varying its Position property. First, the polar axes are shifted downward within the figure to make room for the title. Then the handle to the axes’ title is accessed, and its Position property is shifted to move it upwards so it no longer overlaps the polar axes.
The following code can be added to the above example to accomplish the workaround.
% Shift the polar plot downward within the figure (to make room for title)
currentAxesPosition=get(hAxes2,'Position'); % Get the axes' (polar plot) current position
set(hAxes2,'Position',currentAxesPosition+[0 -0.04 0 0]); % Shift that position downward
% Shift the title upward so it is no longer obscured
title2=get(hAxes2,'Title'); % Get handle to the title object
currentTitlePosition=get(title2,'Position'); % Get the title's current position
set(title2,'Position',currentTitlePosition+[0.45 0 0]); % Shift the position upward
As an alternative, the entire (invisible) axis may be rescaled to remove the overlap without having to adjust the positioning. For example:
figure;
polar(linspace(0,2*pi,100),3*ones(1,100))
%since 3 is the largest radius, rescale the xaxis to be slightly larger that -3 to 3:
xlim([-3.25 3.25])
title('No Overalp')

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2010b

Community Treasure Hunt

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

Start Hunting!