3

In order to find quickly the location of my data, I display a table with my variables names as well as informations about each.

Since I have a lot of columns (variable) I copy and paste blocks of it in a cell to have them all on 1 screen.

I would like to code this, such that I would input several range of Rows to be extracted and efficiently displayed some how on a Grid that would fit an area of the screen ? I have failed yet to display 2 grid nicely together.

In case I did not express my problem properly above, here is a simple example:

How can I move the blue part to the side of the pink one if the output of laList is what we have to deal with ?

co1    = Range[6];
co2    = Range[11, 16];
co3    = {"A", "B", "C", "D", "E", "F"};

laList = Join[{co1}, {co2}, {co3}] // Transpose;

laListGraph = Grid[laList,
Dividers -> All,
Alignment -> {Left, Center},
ItemSize -> Automatic,
ItemStyle -> Directive[FontSize -> 14, Black, Italic, Bold],
Spacings -> {2, 1},
 Background -> {None, None, {
     {{1, 3}, {1, 3}} -> LightRed,
     {{4, 6}, {1, 3}} -> LightBlue
   } } ]
500
  • 6,509
  • 8
  • 46
  • 80
  • Louis, unlike regular forums, there is no need to sign your posts with hi and bye and your name (because each post has your username under it). We're always on good terms, so the hi and bye are implied :) – abcd May 26 '11 at 05:26

3 Answers3

4

EDIT:

On second thoughts, what I had earlier is not what you wanted... you want it displayed as columns, but with the second half of the rows split and displayed beside the first. The following code should do that. Let me know if this is what you had in mind...

(Grid[#1, Dividers -> All, Alignment -> {Left, Center}, 
     ItemSize -> Automatic, 
     ItemStyle -> Directive[FontSize -> 14, Black, Italic, Bold], 
     Spacings -> {2, 1}, 
     Background -> {None, 
       None, {{1, 3}, {1, 3}} -> #2}] &) @@@ {{laList[[;; 3, All]], 
    LightRed}, {laList[[4 ;;, All]], LightBlue}} // Row

enter image description here

Community
  • 1
  • 1
abcd
  • 41,765
  • 7
  • 81
  • 98
4

As I understood your question, the coloring was there just to show us which portion you want to "move up". So:

showG[l_List] :=
  Grid[Join[
    l[[ ;; IntegerPart[Length@l/2]]],
    l[[IntegerPart[Length@l/2] + 1 ;;]]
    , 2], Frame -> All];

showG[laList]

enter image description here

Edit

Or more to @Mr.'s taste:

showG[l_List] :=
  Grid[Join[l[[ ;; #]], l[[# + 1 ;;]], 2], Frame -> All] &@ Floor[Length@l/2];
Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190
  • I really had not considered that interpretation, but you may be right. Remove the redundancy in your code and I'll +1 it. Also, `Floor` is shorter than `IntegerPart`; is there a reason you use the latter? – Mr.Wizard May 26 '11 at 12:11
  • @Mr. Many years ago I worked in an obscure language that used floating point representation for the `Floor` argument. There was a weird bug that _sometimes_ showed up producing (for integers) `Floor[n] == n-1`, and it kept me awake a few nights. Since then, I shiver each time I see `Floor[ ]`. – Dr. belisarius May 26 '11 at 12:49
  • I think I ran into the same thing. Please see the comments to this and tell me if it is so: http://stackoverflow.com/questions/6095959/concatenate-two-integers-in-mathematica-7/6095974#6095974 – Mr.Wizard May 26 '11 at 13:00
  • @Mr. Seems a similar issue, but mine happened many years before Mma materialization :D – Dr. belisarius May 26 '11 at 13:09
  • Mathematica has me spoiled with arbitrary precision. I couldn't figure out why I got that error until I remembered that it was impossible to represent the precise decimal integer in binary. – Mr.Wizard May 26 '11 at 13:14
1

Here is how I would do it. Starting with your laList as defined in the question:

laList2 = ArrayFlatten @ {Partition[laList, 3]};

Grid[laList2,
Dividers -> All,
Alignment -> {Left, Center},
ItemSize -> Automatic,
ItemStyle -> Directive[FontSize -> 14, Black, Italic, Bold],
Spacings -> {2, 1},
 Background -> {None, None, {
     {{1, 3}, {1, 3}} -> LightRed,
     {{1, 3}, {4, 6}} -> LightBlue
   } }
]

enter image description here

Please notice:

  • the value 3 within Partition will need to be adjusted according to your list.

  • the region specification for the LightBlue area was reversed.


A variation of yoda's code I like is:

subgrid= Grid[#1,
         Dividers  -> All,
         Alignment -> {Left, Center}, 
         ItemSize  -> Automatic, 
         ItemStyle -> Directive[FontSize -> 14, Black, Italic, Bold], 
         Spacings  -> {2, 1}, 
         Background-> #2] &;

MapThread[subgrid, {Partition[laList, 3], {LightRed, LightBlue}}] //Row

Also, with this method you can partition a list that does not divide evenly:

MapThread[subgrid, {
  Partition[laList, 4, 4, 1, {}],
  {LightRed, LightBlue}
}] //Row

enter image description here

Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125