Grid: different background color (of row) based on valuesGrid - change entire row background color based on...

Is it theoretically possible to hack printer using scanner tray?

What are the children of two Muggle-borns called?

What happens if a caster is surprised while casting a spell with a long casting time?

What prevents a US state from colonizing a smaller state?

Why are symbols not written in words?

Why am I getting an electric shock from the water in my hot tub?

Is this house-rule removing the increased effect of cantrips at higher character levels balanced?

I just started; should I accept a farewell lunch for a coworker I don't know?

Installed software from source, how to say yum not to install it from package?

Fast method to cut/shred glue stick into small pieces

Why are examinees often not allowed to leave during the start and end of an exam?

Why is exile often an intermediate step?

Could all three Gorgons turn people to stone, or just Medusa?

How far can gerrymandering go?

Is it OK to throw pebbles and stones in streams, waterfalls, ponds, etc.?

Have any large aeroplanes been landed — safely and without damage — in locations that they could not be flown away from?

The alcoholic village festival

How can an inexperienced GM keep a game fun for experienced players?

How does mmorpg store data?

Would skyscrapers tip over if people fell sideways?

Is my guitar action too high or is the bridge too high?

A quine of sorts

Can I submit a paper to two or more journals at the same time?

German idiomatic equivalents of 能骗就骗 (if you can cheat, then cheat)



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













2












$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.










share|improve this question









$endgroup$

















    2












    $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.










    share|improve this question









    $endgroup$















      2












      2








      2





      $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.










      share|improve this question









      $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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 8 hours ago









      Bemtevi77Bemtevi77

      897 bronze badges




      897 bronze badges






















          3 Answers
          3






          active

          oldest

          votes


















          3












          $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]


          enter image description here






          share|improve this answer











          $endgroup$





















            2












            $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}]


            enter image description here






            share|improve this answer









            $endgroup$





















              1












              $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]]


              enter image description here






              share|improve this answer









              $endgroup$
















                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
                });


                }
                });














                draft saved

                draft discarded


















                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









                3












                $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]


                enter image description here






                share|improve this answer











                $endgroup$


















                  3












                  $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]


                  enter image description here






                  share|improve this answer











                  $endgroup$
















                    3












                    3








                    3





                    $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]


                    enter image description here






                    share|improve this answer











                    $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]


                    enter image description here







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    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























                        2












                        $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}]


                        enter image description here






                        share|improve this answer









                        $endgroup$


















                          2












                          $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}]


                          enter image description here






                          share|improve this answer









                          $endgroup$
















                            2












                            2








                            2





                            $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}]


                            enter image description here






                            share|improve this answer









                            $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}]


                            enter image description here







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 8 hours ago









                            MelaGoMelaGo

                            1,8561 gold badge1 silver badge7 bronze badges




                            1,8561 gold badge1 silver badge7 bronze badges























                                1












                                $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]]


                                enter image description here






                                share|improve this answer









                                $endgroup$


















                                  1












                                  $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]]


                                  enter image description here






                                  share|improve this answer









                                  $endgroup$
















                                    1












                                    1








                                    1





                                    $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]]


                                    enter image description here






                                    share|improve this answer









                                    $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]]


                                    enter image description here







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered 4 hours ago









                                    kglrkglr

                                    201k10 gold badges230 silver badges459 bronze badges




                                    201k10 gold badges230 silver badges459 bronze badges






























                                        draft saved

                                        draft discarded




















































                                        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.




                                        draft saved


                                        draft discarded














                                        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





















































                                        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







                                        Popular posts from this blog

                                        Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                                        Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                                        Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...