Artur Castiel
Artur Castiel

Reputation: 185

How to auto adjust the axes in polar graphs with Matlab?

I am plotting multiple graphs in the same figure using polar in MATLAB. It works fine but I cannot manage to autoadjust the limits of the graph and I ended up with something like this: enter image description here

Here is a part of my code:

alpha = 0
tmp = [];
matriz = [];

for rad =-pi:0.01:pi
    matriz = [matriz; rad, ganhoComb(alpha,0.2,rad)];
end
tmp = matriz;
teta = tmp(:,1);
ro = tmp(:,2);
graf1 = polar(teta,ro);
grid
set(graf1,'color','black','linewidth',1.4)
hold on ;
title(['\fontsize{14}','Método Lax-Wendroff ']) 


%%
tmp =[]
matriz = []
for rad =-pi:0.01:pi
    matriz = [matriz; rad, ganhoComb(alpha,0.4,rad)];
end
tmp = matriz;
teta = tmp(:,1);
ro = tmp(:,2);
graf2 = polar(teta,ro);
set(graf2,'color','green','linewidth',1.4)

Upvotes: 1

Views: 134

Answers (1)

Mikhail_Sam
Mikhail_Sam

Reputation: 11208

First of all your code is not verifiable, becouse of ganhoComb. What is it?

Your problem - is that using your hold on you fix the plot, so all other graphs will not scale it:

theta  = linspace(0,2*pi,100);
r      = sin(2*theta) .* cos(2*theta);
r_max  = 1;
h_first = polar(theta,r_max*ones(size(theta)));
hold on;
h      = polar(theta, r);
h      = polar(theta, r*2);
h      = polar(theta, r*3); 

enter image description here

So I suggest two solutions:

  1. Create one circle of big size to de sure all your plots will set INTO it. And make it invisible:

     set(h_first, 'Visible', 'Off');
    

it will works but you it will not be a really autoscale.

  1. so second solution - find maximum radius before plotting and start to plot from the biggest one.

Hope, it helps!

Upvotes: 1

Related Questions