How do I set the width of the axes in a polar plot in MATLAB 7.7 (R2008b)?

41 views (last 30 days)
I have created a polar plot in MATLAB using the POLAR function and now I am trying to set the 'LineWidth' property of the axes but it is not working.
Reproduction steps:
t = 0:.01:2*pi;
polar(t,sin(2*t).*cos(2*t),'--r')
set(gca,'LineWidth',3)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 28 Sep 2011
Polar plots in MATLAB are different from plots on cartesian axes. In order to change the width of the axes in a polar plot, please use the FINDALL command to find the line objects in the figure. Then set the 'LineWidth' of each line object individually in a FOR-loop as shown in the example below:
t = 0:.01:2*pi;
h = polar(t,sin(2*t).*cos(2*t),'--r');
hlines = findall(gcf,'Type','line');
for i = 1:length(hlines)
set(hlines(i),'LineWidth',3);
end
Note that the code above will also set the 'LineWidth' property of the plotted line to 3. To specify a different value, you can do one of the following:
1) Reset the 'LineWidth' property of the plotted line after the FOR loop. This will overwrite the value previously set in the FOR loop. For example, add the following line after the FOR loop:
set(h,'LineWidth',1); %sets the 'LineWidth' property of the plotted line only
OR
2) Include an IF statement in the FOR loop to check that the handle being changed is not the handle of the plotted line. For example, replace the FOR loop in the code above by the following lines:
for i = 1:length(hlines)
if hlines(i) ~= h
set(hlines(i),'LineWidth',3);
end
end

More Answers (0)

Categories

Find more on Polar Plots in Help Center and File Exchange

Products


Release

R2008b

Community Treasure Hunt

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

Start Hunting!