Reputation: 43
How to draw multiple polar plots in one figure in matlab?
polar(polar_mat,dir_mat)
hold all;
polar(polar_mat,dir_mat_b,'r')
Above code draws the second plot only.
Upvotes: 3
Views: 11281
Reputation: 7751
Here is a way to plot several polar graphs in a single figure. I used subplot
to illustrate the different example. We can see that hold on/all
does not work as expected for polar plots (see subplot, top right). Your problem may be related to that. One workaround is to plot the biggest polar graph first and then plot the smallest one.
(subplot 1) Plotting consecutively two lines (plot
) in a single axes with hold all
==> automatic resizing of axes when the second line is plotted
(subplot 2) Plotting consecutively two polar
does not trigger an automatic resizing when the second graph is plotted. We only see a blue line over 0
.
(subplot 3) It plots the second polar
graph alone (blue). This is what we should see.
(subplot 4) Putting the two polar
graphs together, the second one (blue) being plotted first. The axes' properties are set with the blue plot (biggest), and the red one (smallest) is draw on it.
What I still don't understand in your question is that it "draws the second plot only". According to the scenario described here, it should be "draws the first only, and partially the second one". Finally, as read in the comments, the hold on/all
works fine for many users including me - could therefore be a bug in your matlab install.
Here is the plots
and the code
figure('Color','w','Position',[10 10 600 600]);
subplot(2,2,1);
plot((1:10)+1000,'r');
hold all;
plot((1:100).^2,'b');
legend({'first axes';'second axes'});
title('axes resized with hold all','FontSize',14);
subplot(2,2,2);
t = 0:.01:2*pi;
polar(t,sin(2*t).*cos(2*t),'r')
hold all
polar(t,t.^0.1,'b')
title('axes NOT resized with hold all','FontSize',14);
subplot(2,2,3);
polar(t,t.^0.1,'b')
title('what blue should be','FontSize',14);
subplot(2,2,4);
h2 = polar(t,t.^0.1,'b')
hold all;
h1 = polar(t,sin(2*t).*cos(2*t),'r')
title('plot bigger first','FontSize',14);
Upvotes: 2