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
Position representation of spin states and spin operators
How do I keep a running total of data in a column in Excel?
How do I make conditions based on list options?
How does the 'five minute adventuring day' affect class balance?
Avoiding repetition when using the "snprintf idiom" to write text
Do electrons really perform instantaneous quantum leaps?
Is it advisable to inform the CEO about his brother accessing his office?
Where to connect the fuse and why?
Why should I allow multiple IPs on a website for a single session?
What happens if a caster is surprised while casting a spell with a long casting time?
How can an inexperienced GM keep a game fun for experienced players?
Having to constantly redo everything because I don't know how to do it
Calculus, water poured into a cone: Why is the derivative non-linear?
Does friction always oppose motion?
Customs and immigration on a USA-UK-Sweden flight itinerary
Why didn't Caesar move against Sextus Pompey immediately after Munda?
"I am [the / an] owner of a bookstore"?
Checkmate in 1 on a Tangled Board
Is it possible to alias a column based on the result of a select+where?
Does "boire un jus" tend to mean "coffee" or "juice of fruit"?
Hard for me to understand one tip written in "The as-if rule" of cppreference
Rear derailleur got caught in the spokes, what could be a root cause
I agreed to cancel a long-planned vacation (with travel costs) due to project deadlines, but now the timeline has all changed again
How far can gerrymandering go?
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 8 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 7 hours ago
answered 8 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 7 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 4 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