Help about legend in 7.1.0

I would like to plot with legend like this on 7.1.0
(The below works 6.4.0 but does not work on 7.1.0)

clf;
hold on; 
for i = 0:20
  clr=mod(i,5);
  plot([i i+2], sprintf('%d;%d;',clr,i));
end

Please suggest me an alternative way on 7.1.0.

In Octave 7, support for referencing colors using an integer has been removed. You must explicitly specifiy the color using a symbolic char or predefined color name (“b” or “blue”, “k” or “black”, … See format argument in plot function doc) or use the “color” property and provide it an RGB triplet.

Your code would become:

clf;
char_colors = {"k", "m", "b", "g", "r"};
hold on; 
for i = 0:20
  clr = char_colors{mod (i,5) + 1};
  plot([i i+2], sprintf('%s;%d;',clr,i));
end

or

clf;
rgb_colors = [0 0 0;
              1 0 1;
              0 0 1;
              0 1 0;
              1 0 0 ];
hold on; 
for i = 0:20
  clr = rgb_colors(mod (i,5) + 1, :);
  plot([i i+2], sprintf(';%d;',i), "color", clr);
end

or you could avoid having to mess with this rolling color buffer and leave plot do the job for you by predefining the colororder:

clf;
set (gca, "colororder", [0 0 0;1 0 1; 0 0 1; 0 1 0; 1 0 0 ]);
hold on; 
for i = 0:20
  plot([i i+2], sprintf(';%d;',i));
end

Pantxo

Thank you for your reply and examples.