Grid: different background color (of row) based on valuesGrid - change entire row background color based on values on one column?Build a refined grid based on intersecting lineInteractively select a row/column of a GridDraw grid lines at multiples of kGrid - change entire row background color based on values on one column?Is there a way to exert finer control Dataset Cell Coloration Like in Grid?Equalizing the column widths in the rows below the title row of a gridAlign two Grids in a RowDynamically selecting Rows from a GridHow to substitute curly brackets with round brackets in a grid of listConnect grid with dataset to change grid background
Can US Supreme Court justices / judges be "rotated" out against their will?
What overwrites /etc/resolv.conf roughly every hour?
Calculus, water poured into a cone: Why is the derivative non-linear?
The alcoholic village festival
How to track mail undetectably?
What does 'in attendance' mean on an England death certificate?
Fast method to cut/shred glue stick into small pieces
Can I submit a paper to two or more journals at the same time?
Does "boire un jus" tend to mean "coffee" or "juice of fruit"?
Word ending in "-ine" for rat-like
Is it OK to say "The situation is pregnant with a crisis"?
Did the Russian Empire have a claim to Sweden? Was there ever a time where they could have pursued it?
How does the 'five minute adventuring day' affect class balance?
Why are examinees often not allowed to leave during the start and end of an exam?
A* pathfinding algorithm too slow
Why would Dementors torture a Death Eater if they are loyal to Voldemort?
Why will we fail creating a self sustaining off world colony?
How far can gerrymandering go?
How useful would a hydroelectric power plant be in the post-apocalypse world?
Would skyscrapers tip over if people fell sideways?
Why do movie directors use brown tint on Mexico cities?
Is it advisable to inform the CEO about his brother accessing his office?
Is it possible to alias a column based on the result of a select+where?
Why didn't Caesar move against Sextus Pompey immediately after Munda?
Grid: different background color (of row) based on values
Grid - change entire row background color based on values on one column?Build a refined grid based on intersecting lineInteractively select a row/column of a GridDraw grid lines at multiples of kGrid - change entire row background color based on values on one column?Is there a way to exert finer control Dataset Cell Coloration Like in Grid?Equalizing the column widths in the rows below the title row of a gridAlign two Grids in a RowDynamically selecting Rows from a GridHow to substitute curly brackets with round brackets in a grid of listConnect grid with dataset to change grid background
$begingroup$
I want to use Grid
to tabulate the following list
and have the same background color for rows of the same value on column 4.
The actual list
is very long.
list=
1, 2, 1, 1, 1, 0, -1, 1, 4.48,
2, -2, -1, -1, -1, 0, 1, -1, 4.48,
3, 2, 1, 1, 1, 0, -1, 1, 4.48,
4, -2, -1, -1, -1, 0, 1, -1, 4.48,
9, -2, -1, 1, -1, 0, 1, 1, 4.48,
10, 2, 1, -1, 1, 0, -1, -1, 4.48,
11, 2, 1, -1, 1, 0, -1, -1, 4.48,
12, -2, -1, 1, -1, 0, 1, 1, 4.48,
5, 0, -1, 0, 1, -2, 1, 0, 5.266,
6, 0, -1, 0, 1, -2, 1, 0, 5.266,
7, 0, 1, 0, -1, 2, -1, 0, 5.266,
8, 0, 1, 0, -1, 2, -1, 0, 5.266,
5, 1, -4, 0, 2, -3, 1, 0, 5.6323,
6, 1, -4, 0, 2, -3, 1, 0, 5.6323,
7, -1, 4, 0, -2, 3, -1, 0, 5.6323,
8, -1, 4, 0, -2, 3, -1, 0, 5.6323
I found a solution to a similar question here. I wonder how can I build the colorrules
elegantly. Thanks.
grid-layouts
$endgroup$
add a comment |
$begingroup$
I want to use Grid
to tabulate the following list
and have the same background color for rows of the same value on column 4.
The actual list
is very long.
list=
1, 2, 1, 1, 1, 0, -1, 1, 4.48,
2, -2, -1, -1, -1, 0, 1, -1, 4.48,
3, 2, 1, 1, 1, 0, -1, 1, 4.48,
4, -2, -1, -1, -1, 0, 1, -1, 4.48,
9, -2, -1, 1, -1, 0, 1, 1, 4.48,
10, 2, 1, -1, 1, 0, -1, -1, 4.48,
11, 2, 1, -1, 1, 0, -1, -1, 4.48,
12, -2, -1, 1, -1, 0, 1, 1, 4.48,
5, 0, -1, 0, 1, -2, 1, 0, 5.266,
6, 0, -1, 0, 1, -2, 1, 0, 5.266,
7, 0, 1, 0, -1, 2, -1, 0, 5.266,
8, 0, 1, 0, -1, 2, -1, 0, 5.266,
5, 1, -4, 0, 2, -3, 1, 0, 5.6323,
6, 1, -4, 0, 2, -3, 1, 0, 5.6323,
7, -1, 4, 0, -2, 3, -1, 0, 5.6323,
8, -1, 4, 0, -2, 3, -1, 0, 5.6323
I found a solution to a similar question here. I wonder how can I build the colorrules
elegantly. Thanks.
grid-layouts
$endgroup$
add a comment |
$begingroup$
I want to use Grid
to tabulate the following list
and have the same background color for rows of the same value on column 4.
The actual list
is very long.
list=
1, 2, 1, 1, 1, 0, -1, 1, 4.48,
2, -2, -1, -1, -1, 0, 1, -1, 4.48,
3, 2, 1, 1, 1, 0, -1, 1, 4.48,
4, -2, -1, -1, -1, 0, 1, -1, 4.48,
9, -2, -1, 1, -1, 0, 1, 1, 4.48,
10, 2, 1, -1, 1, 0, -1, -1, 4.48,
11, 2, 1, -1, 1, 0, -1, -1, 4.48,
12, -2, -1, 1, -1, 0, 1, 1, 4.48,
5, 0, -1, 0, 1, -2, 1, 0, 5.266,
6, 0, -1, 0, 1, -2, 1, 0, 5.266,
7, 0, 1, 0, -1, 2, -1, 0, 5.266,
8, 0, 1, 0, -1, 2, -1, 0, 5.266,
5, 1, -4, 0, 2, -3, 1, 0, 5.6323,
6, 1, -4, 0, 2, -3, 1, 0, 5.6323,
7, -1, 4, 0, -2, 3, -1, 0, 5.6323,
8, -1, 4, 0, -2, 3, -1, 0, 5.6323
I found a solution to a similar question here. I wonder how can I build the colorrules
elegantly. Thanks.
grid-layouts
$endgroup$
I want to use Grid
to tabulate the following list
and have the same background color for rows of the same value on column 4.
The actual list
is very long.
list=
1, 2, 1, 1, 1, 0, -1, 1, 4.48,
2, -2, -1, -1, -1, 0, 1, -1, 4.48,
3, 2, 1, 1, 1, 0, -1, 1, 4.48,
4, -2, -1, -1, -1, 0, 1, -1, 4.48,
9, -2, -1, 1, -1, 0, 1, 1, 4.48,
10, 2, 1, -1, 1, 0, -1, -1, 4.48,
11, 2, 1, -1, 1, 0, -1, -1, 4.48,
12, -2, -1, 1, -1, 0, 1, 1, 4.48,
5, 0, -1, 0, 1, -2, 1, 0, 5.266,
6, 0, -1, 0, 1, -2, 1, 0, 5.266,
7, 0, 1, 0, -1, 2, -1, 0, 5.266,
8, 0, 1, 0, -1, 2, -1, 0, 5.266,
5, 1, -4, 0, 2, -3, 1, 0, 5.6323,
6, 1, -4, 0, 2, -3, 1, 0, 5.6323,
7, -1, 4, 0, -2, 3, -1, 0, 5.6323,
8, -1, 4, 0, -2, 3, -1, 0, 5.6323
I found a solution to a similar question here. I wonder how can I build the colorrules
elegantly. Thanks.
grid-layouts
grid-layouts
asked 10 hours ago
Bemtevi77Bemtevi77
897 bronze badges
897 bronze badges
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
$begingroup$
Here is a solution with Item[...]
:
itemRules =
With[color = RandomColor[],
(x : ___, #) :> (Item[#,Background -> color] & /@ x)] & /@ Union[list[[All, 4]]];
Grid[list /. itemRules, Dividers -> All]
$endgroup$
add a comment |
$begingroup$
sets = GatherBy[Transpose[Range[Length[list]], list[[All, 4]]], #[[2]] &];
colors = LightYellow, LightOrange, LightBlue;
colorrules =
Flatten@Table[
Thread[sets[[n, All, 1]] -> colors[[n]]], n, Length[sets]];
Grid[list, Frame -> All, Background -> None, colorrules]
$endgroup$
add a comment |
$begingroup$
Using Association
and Lookup
to specify row backgrounds:
keys = Union @ list[[All, -1]];
colors = Lighter @* Lighter @* ColorData["Rainbow"] /@ Rescale[keys];
backgroundColors = AssociationThread[keys, colors];
Legended[Grid[list, Frame -> All,
Background -> None, Lookup[list[[All, -1]]] @ backgroundColors],
SwatchLegend[colors, keys]]
$endgroup$
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f201189%2fgrid-different-background-color-of-row-based-on-values%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
Here is a solution with Item[...]
:
itemRules =
With[color = RandomColor[],
(x : ___, #) :> (Item[#,Background -> color] & /@ x)] & /@ Union[list[[All, 4]]];
Grid[list /. itemRules, Dividers -> All]
$endgroup$
add a comment |
$begingroup$
Here is a solution with Item[...]
:
itemRules =
With[color = RandomColor[],
(x : ___, #) :> (Item[#,Background -> color] & /@ x)] & /@ Union[list[[All, 4]]];
Grid[list /. itemRules, Dividers -> All]
$endgroup$
add a comment |
$begingroup$
Here is a solution with Item[...]
:
itemRules =
With[color = RandomColor[],
(x : ___, #) :> (Item[#,Background -> color] & /@ x)] & /@ Union[list[[All, 4]]];
Grid[list /. itemRules, Dividers -> All]
$endgroup$
Here is a solution with Item[...]
:
itemRules =
With[color = RandomColor[],
(x : ___, #) :> (Item[#,Background -> color] & /@ x)] & /@ Union[list[[All, 4]]];
Grid[list /. itemRules, Dividers -> All]
edited 9 hours ago
answered 9 hours ago
andre314andre314
12.6k1 gold badge24 silver badges53 bronze badges
12.6k1 gold badge24 silver badges53 bronze badges
add a comment |
add a comment |
$begingroup$
sets = GatherBy[Transpose[Range[Length[list]], list[[All, 4]]], #[[2]] &];
colors = LightYellow, LightOrange, LightBlue;
colorrules =
Flatten@Table[
Thread[sets[[n, All, 1]] -> colors[[n]]], n, Length[sets]];
Grid[list, Frame -> All, Background -> None, colorrules]
$endgroup$
add a comment |
$begingroup$
sets = GatherBy[Transpose[Range[Length[list]], list[[All, 4]]], #[[2]] &];
colors = LightYellow, LightOrange, LightBlue;
colorrules =
Flatten@Table[
Thread[sets[[n, All, 1]] -> colors[[n]]], n, Length[sets]];
Grid[list, Frame -> All, Background -> None, colorrules]
$endgroup$
add a comment |
$begingroup$
sets = GatherBy[Transpose[Range[Length[list]], list[[All, 4]]], #[[2]] &];
colors = LightYellow, LightOrange, LightBlue;
colorrules =
Flatten@Table[
Thread[sets[[n, All, 1]] -> colors[[n]]], n, Length[sets]];
Grid[list, Frame -> All, Background -> None, colorrules]
$endgroup$
sets = GatherBy[Transpose[Range[Length[list]], list[[All, 4]]], #[[2]] &];
colors = LightYellow, LightOrange, LightBlue;
colorrules =
Flatten@Table[
Thread[sets[[n, All, 1]] -> colors[[n]]], n, Length[sets]];
Grid[list, Frame -> All, Background -> None, colorrules]
answered 9 hours ago
MelaGoMelaGo
1,8561 gold badge1 silver badge7 bronze badges
1,8561 gold badge1 silver badge7 bronze badges
add a comment |
add a comment |
$begingroup$
Using Association
and Lookup
to specify row backgrounds:
keys = Union @ list[[All, -1]];
colors = Lighter @* Lighter @* ColorData["Rainbow"] /@ Rescale[keys];
backgroundColors = AssociationThread[keys, colors];
Legended[Grid[list, Frame -> All,
Background -> None, Lookup[list[[All, -1]]] @ backgroundColors],
SwatchLegend[colors, keys]]
$endgroup$
add a comment |
$begingroup$
Using Association
and Lookup
to specify row backgrounds:
keys = Union @ list[[All, -1]];
colors = Lighter @* Lighter @* ColorData["Rainbow"] /@ Rescale[keys];
backgroundColors = AssociationThread[keys, colors];
Legended[Grid[list, Frame -> All,
Background -> None, Lookup[list[[All, -1]]] @ backgroundColors],
SwatchLegend[colors, keys]]
$endgroup$
add a comment |
$begingroup$
Using Association
and Lookup
to specify row backgrounds:
keys = Union @ list[[All, -1]];
colors = Lighter @* Lighter @* ColorData["Rainbow"] /@ Rescale[keys];
backgroundColors = AssociationThread[keys, colors];
Legended[Grid[list, Frame -> All,
Background -> None, Lookup[list[[All, -1]]] @ backgroundColors],
SwatchLegend[colors, keys]]
$endgroup$
Using Association
and Lookup
to specify row backgrounds:
keys = Union @ list[[All, -1]];
colors = Lighter @* Lighter @* ColorData["Rainbow"] /@ Rescale[keys];
backgroundColors = AssociationThread[keys, colors];
Legended[Grid[list, Frame -> All,
Background -> None, Lookup[list[[All, -1]]] @ backgroundColors],
SwatchLegend[colors, keys]]
answered 5 hours ago
kglrkglr
201k10 gold badges230 silver badges459 bronze badges
201k10 gold badges230 silver badges459 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f201189%2fgrid-different-background-color-of-row-based-on-values%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown