The order of the commands matter sometimes

From Octave
Jump to: navigation, search

When you plot many curves in an automated way, you might want to also have automatic control over the colors of these curves:

x=(1:20)';
N=1:5;
for n=N
 y(:,n)=x.**n;
endfor
%
semilogy(x,y)
%
K=rainbow(length(N));
set(gca,'colororder',K)
xlabel('\delta \epsilon \times foo')
title('some non-sense with the standard colors still') 

This shows that the xlabel() and the title() can be added after the plotting of the curves is done, but the set()ting of the 'colororder' is not done. That is: the setting of the 'colororder' is done, but not applied until the next command for plotting something is executed.

Solution: You need to set() the 'colororder' before the plot() command (or in this case the semilogy() command):

x=(1:20)';
N=1:5;
for n=N
 y(:,n)=x.**n;
endfor
%
K=rainbow(length(N));
set(gca,'colororder',K)
%
semilogy(x,y)
%
xlabel('\delta \epsilon \times foo')
title('some non-sense but with colors THAT I WANTED')