Search code examples
plotscilab

Colormap in 2d plots in Scilab


When using the plot(y) function in Scilab, being y a real matrix, multiple data curves are plotted on a 2d plot and the color of each curve is automatically set.

According to Scilab online help, a default color table is used (the command cycles the table and colors each curve accordingly):
http://help.scilab.org/docs/5.5.2/en_US/plot.html

The problem is that the default table lists only 7 colors, so the 8th data curve will have the same color as the 1st, and so on.

Is there a way to extend this table, to automatically color more than 7 data curves with distinct colors?

I tried using the colormap as in 3d plots, but didn't worked.

f = scf();
plot(myData);
f.color_map = jetcolormap(32);

I think this only works for 3d plots.


Solution

  • You can use a for loop to set the foreground color using gce().

    Example

    clf()
    
    number_of_points=100;
    number_of_lines=42;
    
    x=[1:number_of_points]
    
    for line_number = 1:number_of_lines
        plot(x, x+line_number);
        last_line = gce();
        last_line.children.foreground = line_number;
    end
    
    f = gcf();
    f.color_map= jetcolormap(number_of_lines);
    

    Result

    Plot