Dividing lists into data sets and plotting


  • administrators

    If you have a comma separated dataset that contains X values and two sets of Y values for each X. I need to create two new data sets with X and Y values. You can pull out each set using the subsop and seq commands.

    Here is my data set

    $data="[10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320, 330, 340, 350, 360, 370, 380, 390, 400, 410, 420, 430, 440, 450, 460, 470, 480, 490, 500]";
    

    I want to divide this into three data sets

    X 10, 40, 70 ...

    Y1 20,50,80...

    Y2 30,60,90..

    To do this, first we divide the data sets

    $m=maple("
    K := $data;
    X := subsop(seq(`if`(`mod`(i, 3) = 1, NULL, i = NULL), i = 1 .. nops(K)), K);
    Y1 := subsop(seq(`if`(`mod`(i, 3) = 2, NULL, i = NULL), i = 1 .. nops(K)), K);
    Y2 := subsop(seq(`if`(`mod`(i, 3) = 0, NULL, i = NULL), i = 1 .. nops(K)), K);
    ");
    


    To plot one of these series we can use

    plot(Vector(X), Vector(Y1), style = point, symbol = asterisk, color = `blue`)
    

    To plot both on the same graph we can use the plots[display] function.

    plots[display](
    plot(Vector(X), Vector(Y1), style = point, symbol = asterisk, color = `blue`),
    plot(Vector(X), Vector(Y2), style = point, symbol = asterisk, color = `red`)
    )
    

    The full code looks like this

    $data="[10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300, 310, 320, 330, 340, 350, 360, 370, 380, 390, 400, 410, 420, 430, 440, 450, 460, 470, 480, 490, 500]";
    $m=plotmaple("
    K := $data:
    X := subsop(seq(`if`(`mod`(i, 3) = 1, NULL, i = NULL), i = 1 .. nops(K)), K):
    Y1 := subsop(seq(`if`(`mod`(i, 3) = 2, NULL, i = NULL), i = 1 .. nops(K)), K):
    Y2 := subsop(seq(`if`(`mod`(i, 3) = 0, NULL, i = NULL), i = 1 .. nops(K)), K):
    plots[display](
    plot(Vector(X), Vector(Y1), style = point, symbol = asterisk, color = `blue`),
    plot(Vector(X), Vector(Y2), style = point, symbol = asterisk, color = `red`)
    )
    ");
    
    

    The result is




Log in to reply