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













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 10 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 9 hours ago

























                    answered 9 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 9 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 5 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

                                        Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                                        Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                                        Ласкавець круглолистий Зміст Опис | Поширення | Галерея | Примітки | Посилання | Навігаційне меню58171138361-22960890446Bupleurum rotundifoliumEuro+Med PlantbasePlants of the World Online — Kew ScienceGermplasm Resources Information Network (GRIN)Ласкавецькн. VI : Літери Ком — Левиправивши або дописавши її