8
$\begingroup$

I have the following code, which produce the image shown.

Labeled[GraphicsGrid[{{Fig1A, Fig1B, Fig1C}, {Fig1D, Fig1E, Fig1F}, {Fig1G, Fig1H, Fig1I}}, Spacings -> {0, 0}, Frame -> None, AspectRatio -> 1], {Pane["Too far out, and I need a label (centered) for each row"],"Fine!" , "This is fine, except I need a label (centered) for each column"}, \{Left, Bottom, Top}, RotateLabel -> True, LabelStyle -> [![enter image description here][1]][1]Directive[Bold, FontFamily -> "Consolas", FontSize -> 16]]

The problem (as also summarized in the current labels) is that:

A) There is too much white-space between the chart and the label on the left.

B) I need more than an overarching label at the left and on top. I need centered labels for each row on the left, and centered lablles for each column at the top.

So, overall, I am looking to produce a nice and compact image.

How can I achieve my goal?

UPDATE: I thought setting Spacings -> {-100, 0} worked, but that also makes the plot overlap...

enter image description here

$\endgroup$
3
  • $\begingroup$ Look in my questions, I wonder if you can adapt the frame margins one for this? $\endgroup$ May 23, 2020 at 15:34
  • $\begingroup$ @CATrevillian Could you please provide me the link? $\endgroup$
    – user120911
    May 24, 2020 at 10:13
  • $\begingroup$ Find the relevant answer to the question here. $\endgroup$ May 24, 2020 at 15:31

2 Answers 2

8
$\begingroup$

GraphicsGrid

For me, your GraphicsGrid doesn't have such issues with the spacings:

plots = Table[
  ListLinePlot[
   RandomReal[{-0.3, 0.3}, 10],
   PlotStyle -> {Thick, ColorData[112][i]},
   PlotRange -> {-0.3, 0.3},
   AxesStyle -> Black],
  {i, 3}, {j, 3}
  ]

Labeled[
 GraphicsGrid[
  plots,
  Spacings -> {0, 0},
  Frame -> None,
  AspectRatio -> 1
  ],
 {Pane["Too far out, and I need a label (centered) for each row"], 
  "Fine!", "This is fine, except I need a label (centered) for each \
column"},
 {Left, Bottom, Top},
 RotateLabel -> True,
 LabelStyle -> 
  Directive[Bold, FontFamily -> "Consolas", FontSize -> 16]
 ]

enter image description here

(this is using version 11.3 or 12.0 on Windows)

Now, to add the column/row-wise labels, you can use Labeled on the individual plots:

plots = Table[
  If[i == 1,
       Labeled[#, Row@{"Row ", j}, Top],
       #
       ] &@If[j == 1,
      Labeled[#, Row@{"Column ", i}, Left, RotateLabel -> True],
      #
      ] &@ListLinePlot[
    RandomReal[{-0.3, 0.3}, 10],
    PlotStyle -> {Thick, ColorData[112][i]},
    PlotRange -> {-0.3, 0.3},
    AxesStyle -> Black],
  {i, 3}, {j, 3}
  ]

Labeled[
 GraphicsGrid[
  plots,
  Spacings -> {0, 0},
  Frame -> None,
  AspectRatio -> 1,
  ImageSize -> 600
  ],
 {Pane["Too far out, and I need a label (centered) for each row"], 
  "Fine!", "This is fine, except I need a label (centered) for each \
column"},
 {Left, Bottom, Top},
 RotateLabel -> True,
 LabelStyle -> 
  Directive[Bold, FontFamily -> "Consolas", FontSize -> 16]
 ]

enter image description here

ResourceFunction["PlotGrid"]

Alternatively, you could use ResourceFunction["PlotGrid"] together with FrameLabel on the individual plots and the entire plot-grid to get your labels:

plots = Table[
  ListLinePlot[
   RandomReal[{-0.3, 0.3}, 10],
   PlotStyle -> {Thick, ColorData[112][i]},
   PlotRange -> {-0.3, 0.3},
   Frame -> True,
   FrameStyle -> Black,
   FrameLabel -> {{Row@{"Row ", i}, None}, {None, Row@{"Column ", j}}},
   Axes -> True
   ],
  {i, 3}, {j, 3}
  ]

enter image description here

ResourceFunction["PlotGrid"][
 plots,
 FrameLabel -> {{Pane[
     "Too far out, and I need a label (centered) for each row"], 
    None}, {"Fine!", 
    "This is fine, except I need a label (centered) for each column"}},
 Spacings -> 10,
 ImageSize -> 700,
 "ShowFrameLabels" -> Automatic,
 FrameStyle -> 
  Directive[Black, Bold, FontFamily -> "Consolas", FontSize -> 16],
 AspectRatio -> 1
 ]

enter image description here

Note how the inner labels are automatically hidden, together with the tick labels. If you want all of the tick labels, use "ShowFrameLabels"->Full: (note that this requires hiding the FrameLabels manually)

plots = Table[
  ListLinePlot[
   RandomReal[{-0.3, 0.3}, 10],
   PlotStyle -> {Thick, ColorData[112][i]},
   PlotRange -> {-0.3, 0.3},
   Frame -> True,
   FrameStyle -> Black,
   FrameLabel -> {{If[j == 1, Row@{"Row ", i}, None], None}, {None, 
      If[i == 1, Row@{"Column ", j}, None]}},
   Axes -> True
   ],
  {i, 3}, {j, 3}
  ]

ResourceFunction["PlotGrid"][
 plots,
 FrameLabel -> {{Pane[
     "Too far out, and I need a label (centered) for each row"], 
    None}, {"Fine!", 
    "This is fine, except I need a label (centered) for each column"}},
 Spacings -> 30,
 ImageSize -> 700,
 "ShowFrameLabels" -> Full,
 FrameStyle -> 
  Directive[Black, Bold, FontFamily -> "Consolas", FontSize -> 16],
 AspectRatio -> 1
 ]

enter image description here

Alignment issues

Something similar can of course also be achieved using GraphicsGrid. Note that GraphicsGrid will not properly align the individual plots in versions before 12.0 or when the plots are Labeled:

plots2 = Table[
  If[i == 1,
       Labeled[#, Row@{"Row ", j}, Top],
       #
       ] &@If[j == 1,
      Labeled[#, Row@{"Column ", i}, Left, RotateLabel -> True],
      #
      ] &@ListLinePlot[
    RandomReal[{-0.05, 0.3}, 10],
    PlotStyle -> {Thick, ColorData[112][i]},
    (*PlotRange\[Rule]{-0.3,0.3},*)
    AxesStyle -> Black,
    Frame -> True],
  {i, 3}, {j, 3}
  ]

Labeled[
 GraphicsGrid[
  plots2,
  Spacings -> {0, 0},
  Frame -> None,
  AspectRatio -> 1,
  ImageSize -> 600
  ],
 {Pane["Too far out, and I need a label (centered) for each row"], 
  "Fine!", "This is fine, except I need a label (centered) for each \
column"},
 {Left, Bottom, Top},
 RotateLabel -> True,
 LabelStyle -> 
  Directive[Bold, FontFamily -> "Consolas", FontSize -> 16]
 ]

enter image description here

This issue is only visible if the ImagePadding is not the same for all plots, as is e.g. the case when the plot ranges are not all the same. ResourceFunction["PlotGrid"] will always align the plots properly, but is only available starting from version 11.3 (unless you manually copy the definition somewhere).

$\endgroup$
6
$\begingroup$

Grid should do. Study docs on it for advanced options (Alignment, etc.). Small part for plot definitions (it is always better to provide your own complete code, even a toy sample, so people do not have to make it up and can see important details of your case):

data=RandomReal[{-1,1},{9,10}];
plots=Partition[ListLinePlot[Sort[#],PlotTheme->"Business"]&/@data,3];

And something like this:

{{"","COLUMN1","COLUMN2","COLUMN3"}}~Join~Transpose[{Rotate[#,Pi/2]&/@
{"ROW1","ROW2","ROW3"}}~Join~Transpose[plots]]//Grid

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ Note that Grid will not properly align the plots if their ImagePadding is inconsistent. GraphicsGrid does this properly in versions above 12.0. Of course, this is only an issue if the plot ranges are not all the same (and for GraphicsGrid the alignment also breaks down as soon as you wrap the plots with Labeled or similar). $\endgroup$
    – Lukas Lang
    May 25, 2020 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.