Subscribe Bookmark RSS Feed

Plot a column vs all other ones

razmah

Community Trekker

Joined:

Jul 20, 2015

I have a variable that shows the number of columns Y.

I want to plot x vs all Y.

for example first column is x and A=6 shows that we have 6 Y columns after x.

how to make an overlay plot?

something like:

X( :Distance ),

  Y( (:column 3) :: column (char(A))); hahaha

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

If I understand correctly, something like this should do:

NamesDefaultToHere(1);

// Make some demo data

dt = NewTable("Data",

  NewColumn("y1", Numeric, Continuous, Formula(RandomNormal())),

  NewColumn("y2", Numeric, Continuous, Formula(RandomNormal())),

  NewColumn("x", Numeric, Continuous, Formula(RandomInteger(1, 20))),

  NewColumn("y3", Numeric, Continuous, Formula(RandomNormal())),

  NewColumn("y4", Numeric, Continuous, Formula(RandomNormal())),

  AddRows(10)

);

// Plot every column in dt not called 'x' against "x"

cols = dt << getColumnNames("String");

Remove From(cols, Loc(cols, "x")[1]);

dt << Overlay Plot( X( :x ), Y( Eval(cols) ), Connect Points( 1 ) );


5 REPLIES
Solution

If I understand correctly, something like this should do:

NamesDefaultToHere(1);

// Make some demo data

dt = NewTable("Data",

  NewColumn("y1", Numeric, Continuous, Formula(RandomNormal())),

  NewColumn("y2", Numeric, Continuous, Formula(RandomNormal())),

  NewColumn("x", Numeric, Continuous, Formula(RandomInteger(1, 20))),

  NewColumn("y3", Numeric, Continuous, Formula(RandomNormal())),

  NewColumn("y4", Numeric, Continuous, Formula(RandomNormal())),

  AddRows(10)

);

// Plot every column in dt not called 'x' against "x"

cols = dt << getColumnNames("String");

Remove From(cols, Loc(cols, "x")[1]);

dt << Overlay Plot( X( :x ), Y( Eval(cols) ), Connect Points( 1 ) );


razmah

Community Trekker

Joined:

Jul 20, 2015

Thanks a lot; it works well.

How about graph builder?

When I use graph builder instead of overlay plot it cannot recognize "eval (cols)"

Is there any way for using same concept in graph builder?

louv

Staff

Joined:

Jun 23, 2011

Does this work?

// Make some demo data

dt = NewTable("Data",

  NewColumn("y1", Numeric, Continuous, Formula(RandomNormal())),

  NewColumn("y2", Numeric, Continuous, Formula(RandomNormal())),

  NewColumn("x", Numeric, Continuous, Formula(RandomInteger(1, 20))),

  NewColumn("y3", Numeric, Continuous, Formula(RandomNormal())),

  NewColumn("y4", Numeric, Continuous, Formula(RandomNormal())),

  AddRows(10)

);

Graph Builder(

  Size( 534, 454 ),

  Show Control Panel( 0 ),

  Variables(

  X( :x ),

  Y( :y1 ),

  Y( :y2, Position( 1 ) ),

  Y( :y3, Position( 1 ) ),

  Y( :y4, Position( 1 ) )

  ),

  Elements( Line( X, Y( 1 ), Y( 2 ), Y( 3 ), Y( 4 ), Legend( 51 ) ) )

);


razmah

Community Trekker

Joined:

Jul 20, 2015

Thanks Lou; the problem is I don't have name of columns.  Ian trick is great to use "get column names". but I need to use it in graph builder.

so I cannot use:

Y( :y1 ),

  Y( :y2, Position( 1 ) ),

  Y( :y3, Position( 1 ) ),

  Y( :y4, Position( 1 ) )


great way:

cols = dt << getColumnNames("String");

Remove From(cols, Loc(cols, "x")[1]);

dt << Overlay Plot( X( :x ), Y( Eval(cols) ), Connect Points( 1 ) );


ian_jmp

Staff

Joined:

Jun 23, 2011

The sophistication of Graph Builder inevitably means it's a little more complex to script. Here's one way. I'm confident there are many others.

NamesDefaultToHere(1);

// Make some demo data

dt = NewTable("Data",

  NewColumn("y1", Numeric, Continuous, Formula(RandomNormal())),

  NewColumn("y2", Numeric, Continuous, Formula(RandomNormal())),

  NewColumn("x", Numeric, Continuous, Formula(RandomInteger(1, 20))),

  NewColumn("y3", Numeric, Continuous, Formula(RandomNormal())),

  NewColumn("y4", Numeric, Continuous, Formula(RandomNormal())),

  AddRows(10)

);

// Plot every column in dt not called 'x' against "x"

cols = dt << getColumnNames("String");

Remove From(cols, Loc(cols, "x")[1]);

// Build an expression of the variables we want Graph Builder to use

varExpr = Expr( Variables( X(:x) ) );

For(i = 1, i <= NItems(cols), i++,

  if (i == 1,

  InsertInto(varExpr, Parse(EvalInsert("Y(:^cols^)"))),

  InsertInto(varExpr, Parse(EvalInsert("Y(:^cols^, Position(1))"))) 

  );

  );

// Graph Builder expression . . .

doGB = Expr(dt << Graph Builder(varTBD));

// . . . put the variables into this

SubstituteInto(doGB, Expr(varTBD), EvalExpr(varExpr));

// Make the graph

doGB;