Search code examples
plotgraphscilabcalculuspolar-coordinates

Scilab polarplot of multiple functions does not use different colors for every graph


I'm trying to plot two different polar functions in the same graph, but with different color.

Here's my code:

clear
close
clc
clf
theta=[0:((1*%pi)/180):((359*%pi)/180)];
a=2;
b=3;
rho=a+b*sin(theta);
rro=a-b*sin(theta);
polarplot([theta theta], [real(rho) real(rro)],[27 14]);
xtitle("Caracol con lazo interior");
legends(['r = a+bsen(θ)';'r = a-bsen(θ)'],[27 14],opt=3);

And although the graphs are plotted properly, it only uses the first defined color for both. In this case: 27

Result graph

So, I want one to be orange and the other green.

Can you please tell me how to fix the issue, please? Thanks in advance.


Solution

  • In your code theta is a row vector, and therefore rho and rro are also row vectors. So when you combine them as [theta theta], [real(rho) real(rro)] the result is one curve obtained by concatenating the two curves. Of course it is plotted with one color. The fix is to make theta a column vector:

    theta=[0:((1*%pi)/180):((359*%pi)/180)]';
    

    Then [theta theta] and [real(rho) real(rro)] are matrices with two columns, and the result is as expected; two colors for two curves.