cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP 19 is here! See the new features at jmp.com/new.
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
Choose Language Hide Translation Bar
lala
Level IX

How to set color gradients for specified multiple columns stroke by stroke?

Thanks Experts!

dt=Open("$SAMPLE_DATA/Big Class.jmp");
ca="height1";w=Try(Length(as Column(Current Data Table(),ca)<<get name),0)>0;if(w<1,New Column(ca));Column(ca)<<Formula( height*1.1 );Current Data Table()<<run formulas;Column(ca)<<deleteFormula;

2025-06-08_11-43-38.png

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to set color gradients for specified multiple columns stroke by stroke?

Something like this?

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/SAT.jmp");
dt << Delete Columns({"% Taking (2004)", "X", "Y", "Population", "Latitude", "Longitude"});

l = (dt << Get Column Names("Continuous", "String"))[1::3];
c1 = {"Green", "Yellow", "Red"};
c2 = [];

c3 = [];
For Each Row(dt,
	r = Floor(Ranking Tie(dt[Row(), l])); // no idea what should be done with ties
	c3 = c3 |/ r`;
);

dt << Begin Data Update;
For Each({i, idx}, l,
	m = c3[0, idx];
	g = Loc(m, 1);
	y = Loc(m, 2);
	r = Loc(m, 3);
	Column(dt, i) << Color Cells({{"Green", g}, {"Yellow", y},{"Red", r}});
);
dt << End Data Update;

or like this

/*""" Gradient color cells rowwise (using whole data)

Author: jthi
Creation Date: 2025-06-08
Creation JMP Version: JMP Pro 18.2.0
	
"""*/

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/SAT.jmp");
dt << Delete Columns({"% Taking (2004)", "X", "Y", "Population", "Latitude", "Longitude"});

l = dt << Get Column Names("Continuous", "String");
c = [];
For Each Row(dt,
	m = dt[Row(), l];
	mn = (m - Min(m)) / (Max(m) - Min(m));
	c = c |/ Heat Color(mn, "Cividis");
);

dt << Begin Data Update();
For Each({i, idx}, l,
	cm = {};
	For Each({c, idx}, c[0, idx],
		v = Eval List({c, Eval List({idx})});
		Insert Into(cm, Eval List({v}));
	);
	Eval(EvalExpr(
		Column(dt, i) << Color Cells(Expr(cm));
	));
	
);
dt << End Data Update();
-Jarmo

View solution in original post

10 REPLIES 10
lala
Level IX

回复: How to set color gradients for specified multiple columns stroke by stroke?

AI
not work

dt = Current Data Table();
colRange = {9, 10, 11};
minVals = {};
maxVals = {};
For(i = 1, i <= N Items(colRange), i++,
    col = Column(dt, colRange[i]);
    minVals[i] = Col Min(col);
    maxVals[i] = Col Max(col);
);
get_cell_color = Function({col, r, c},
    s = col << get script;
    p = 0;
    For(i = 1, i <= N Arg(s), i++,
        If(Head Name(Arg(s, i)) == "Color Cells",
            p = i;
            Break();
        );
    );
    If(p != 0,
        L = Arg(Arg(s, p), 1);
        color = {};
        For(i = 1, i <= N Items(L), i++,
            If(N Row(Loc(L[i][2], r)) == 1,
                color = L[i][1];
                Break();
            );
        );
        Return(color);
    ,
        normalized = 0.5;
        If(maxVals[c] != minVals[c],
            normalized = (col[r] - minVals[c]) / (maxVals[c] - minVals[c]);
        );
        red = Round(255 * normalized);
        green = 0;
        blue = Round(255 * (1 - normalized));
        Return(RGB Color(red, green, blue));
    );
);
For Each Row(
    For(i = 1, i <= N Items(colRange), i++,
        colIdx = colRange[i];
        col = Column(dt, colIdx);
        Eval(Parse(Eval Insert("Column(dt, ^colIdx^) << Color Cells({{get_cell_color(Column(dt, ^colIdx^), Row(), ^i^), {Row()}}})")));
    );
);
jthi
Super User

Re: How to set color gradients for specified multiple columns stroke by stroke?

Are you trying to color the cells on a row using color gradient?

-Jarmo
jthi
Super User

Re: How to set color gradients for specified multiple columns stroke by stroke?

No real idea what was requested here, but here is an attempt of a script to row wise gradient coloring

/*""" Gradient color cells rowwise (using whole data)

Author: jthi
Creation Date: 2025-06-08
Creation JMP Version: JMP Pro 18.2.0
	
"""*/

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/SAT.jmp");
dt << Delete Columns({"% Taking (2004)", "X", "Y", "Population", "Latitude", "Longitude"});

cont_cols = dt << Get Column Names("Continuous", "String");
m = dt[0, cont_cols];
mn = (m - Min(m)) / (Max(m) - Min(m));
colors = Heat Color(mn, "Cividis")`;

idx = 0;
dt << Begin Data Update;
For Each({contcol}, cont_cols,
	For Each Row(dt,
		idx++;
		Column(dt, contcol) << Color Cells(colors[idx], Row());
	);
);

dt << End Data Update;
wait(0);
write("\!NDONE");
View more...
jthi_0-1749367102206.png

 

-Jarmo
lala
Level IX

Re: How to set color gradients for specified multiple columns stroke by stroke?

dt = Current Data Table();
colRange = {9, 10, 11};
cont_cols = {};
For( i = 1, i <= N Items( colRange ), i++,
	Insert Into( cont_cols, Column( dt, colRange[i] ) << Get Name );
);
m = dt[0, cont_cols];
mn = (m - Min( m )) / (Max( m ) - Min( m ));
colors = Heat Color( mn, "Green Yellow Red" );
idx = 0;
dt << Begin Data Update;
For Each( {contcol}, cont_cols,
	For Each Row( dt,
		idx++;
		Column( dt, contcol ) << Color Cells( colors[idx], Row() );
	);
);
dt << End Data Update;

Ok.

But it seems that in this way, the entire three columns form a whole

It is not a single row of three cells that form a color whole.

Thanks!

lala
Level IX

Re: How to set color gradients for specified multiple columns stroke by stroke?

Implementing line by line would be too slow

jthi
Super User

Re: How to set color gradients for specified multiple columns stroke by stroke?

What are you trying to do?

-Jarmo
lala
Level IX

Re: How to set color gradients for specified multiple columns stroke by stroke?

2025-06-08_22-37-05.png

The color change of each row is only based on the comparison of the values in the three columns of that row.

Thanks!

jthi
Super User

Re: How to set color gradients for specified multiple columns stroke by stroke?

You have only three values for each row and wish to have just those three colors?

-Jarmo
jthi
Super User

Re: How to set color gradients for specified multiple columns stroke by stroke?

Something like this?

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/SAT.jmp");
dt << Delete Columns({"% Taking (2004)", "X", "Y", "Population", "Latitude", "Longitude"});

l = (dt << Get Column Names("Continuous", "String"))[1::3];
c1 = {"Green", "Yellow", "Red"};
c2 = [];

c3 = [];
For Each Row(dt,
	r = Floor(Ranking Tie(dt[Row(), l])); // no idea what should be done with ties
	c3 = c3 |/ r`;
);

dt << Begin Data Update;
For Each({i, idx}, l,
	m = c3[0, idx];
	g = Loc(m, 1);
	y = Loc(m, 2);
	r = Loc(m, 3);
	Column(dt, i) << Color Cells({{"Green", g}, {"Yellow", y},{"Red", r}});
);
dt << End Data Update;

or like this

/*""" Gradient color cells rowwise (using whole data)

Author: jthi
Creation Date: 2025-06-08
Creation JMP Version: JMP Pro 18.2.0
	
"""*/

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/SAT.jmp");
dt << Delete Columns({"% Taking (2004)", "X", "Y", "Population", "Latitude", "Longitude"});

l = dt << Get Column Names("Continuous", "String");
c = [];
For Each Row(dt,
	m = dt[Row(), l];
	mn = (m - Min(m)) / (Max(m) - Min(m));
	c = c |/ Heat Color(mn, "Cividis");
);

dt << Begin Data Update();
For Each({i, idx}, l,
	cm = {};
	For Each({c, idx}, c[0, idx],
		v = Eval List({c, Eval List({idx})});
		Insert Into(cm, Eval List({v}));
	);
	Eval(EvalExpr(
		Column(dt, i) << Color Cells(Expr(cm));
	));
	
);
dt << End Data Update();
-Jarmo

Recommended Articles