3

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.

Janu
  • 43
  • 1
  • 1
  • 5
  • You can try `hold on`, but the code looks ok to me and it should work. Are u sure that `dir_mat` and `dir_mat_b` are different? – Marcin Sep 02 '13 at 23:57
  • yes. they are different... 'Hold all' does not work for polar plots. It works for other type of plots... – Janu Sep 03 '13 at 00:09
  • So, did `hold on` work? – Roney Michael Sep 03 '13 at 04:36
  • hold on is also not working – Janu Sep 03 '13 at 07:38
  • 2
    Either `hold on` or `hold all` do work in your example (at least in Matlab R2010b, Win7) – Luis Mendo Sep 03 '13 at 08:54
  • @LuisMendo I confirm: both work also to me (Matlab R2010a, Win7). – Vitality Sep 03 '13 at 09:05
  • 1
    Are `dir_mat` and `dir_mat_b` different *enough*? It could just be that `isequal` gives false, but that the absolute difference between the two is so tiny that it is completely invisible in a plot. You can select the red curve (with the "arrow" pointer) and press `delete` on your keyboard. If you then see the curve change color to blue, they simply lie on top of each other. Alternatively, the scaling of the first may be so different, that the entire blue curve lies inside a single pixel in the center. Try zooming in to the center and see if the blue curve appears. – Rody Oldenhuis Sep 03 '13 at 10:07
  • Better yet: just plot them separately, and look at their differences in shape/scaling. That should give you a quick clue as to what's going on. – Rody Oldenhuis Sep 03 '13 at 10:10
  • `hold all` works partially (no automatic axes resizing using `polar`). And there might be a scaling problem as @Rody Oldenhuis pointed out. – marsei Sep 03 '13 at 11:01

1 Answers1

2

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

enter image description here

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);  
marsei
  • 7,691
  • 3
  • 32
  • 41