24
$\begingroup$

I often seek to display two graphs, side by side, with a common label over them. There is no option for adding a label to GraphicsRow, which means, I think, that I need to use Grid or GraphicsGrid and include a row on top that has SpanFromLeft set to allow a graphically defined line of text occupy the entire row.

It seems like a lot of work to do something simple. Is there a better solution?

$\endgroup$
  • 6
    $\begingroup$ You can use Labeled $\endgroup$ – rm -rf Sep 24 '13 at 0:07
12
$\begingroup$

Possibly more versatile, but you have to mess with text overlapping your plots, but GraphicsRow also accepts Epilog

GraphicsRow[{Plot[Sin[x], {x, 0, 4 Pi}], Plot[Cos[x], {x, 0, 4 Pi}]}, 
 Spacings -> Scaled[0.4], 
 Epilog -> Inset["Plot Title", Scaled[{0.5, 0.95}]]]

Mathematica graphics

$\endgroup$
  • 4
    $\begingroup$ PlotRangePadding -> {0, {0, 25}} could help avoid possible text/plot collisions. $\endgroup$ – ssch Sep 24 '13 at 0:24
  • $\begingroup$ @ssch Thanks - I figured there was a padding option, but couldn't put my finger on it. $\endgroup$ – bobthechemist Sep 24 '13 at 0:26
  • $\begingroup$ Since PlotLabel broke in v12, I’ve switched over to this approach. $\endgroup$ – Michael Stern Sep 4 at 17:43
28
$\begingroup$

GraphicsRow takes a PlotLabel option:

p1 = Plot[Sin[x], {x, 0, Pi}, PlotLabel -> Sin];
p2 = Plot[Cos[x], {x, 0, Pi}, PlotLabel -> Cos];
GraphicsRow[{p1, p2}, PlotLabel -> "Two plots"]

enter image description here

$\endgroup$
  • $\begingroup$ I can't imagine how I missed this. Thanks. $\endgroup$ – Michael Stern Sep 24 '13 at 0:36
  • 5
    $\begingroup$ @MichaelStern Easy to miss since it's not in the GraphicsRow documentation :) $\endgroup$ – ssch Sep 24 '13 at 0:38
  • 1
    $\begingroup$ @Michael Indeed, this is the first time I can recall seeing this, so thank you for asking the question! (+1 of course, ssch) $\endgroup$ – Mr.Wizard Sep 24 '13 at 0:50
  • $\begingroup$ As of version 12, this no longer works. Sigh. $\endgroup$ – Michael Stern May 17 at 14:47
10
$\begingroup$

When I need more interface control, I usually do something like this:

p1=Plot[Sin[x],{x,0,Pi},PlotLabel->Sin,ImageSize->150];
p2=Plot[Cos[x],{x,0,Pi},PlotLabel->Cos,ImageSize->150];
title=Panel[Style["Test Label",White,20],ImageSize->300,Background->Orange,Alignment->Center];
Deploy@Grid[{{title,SpanFromLeft},{p1,p2}},Dividers->Gray,Spacings->{0,0}]

enter image description here

$\endgroup$
8
$\begingroup$

Few additional methods:

p1 = Plot[Sin[x], {x, 0, 2 Pi}, ImageSize -> 200];
p2 = Plot[Cos[x], {x, 0, 2 Pi}, ImageSize -> 200];

Labeled

Labeled[Panel@GraphicsRow[{p1, p2}], Style["Label", "Subsubsection"], Top] // Panel

enter image description here

Panel

Panel[GraphicsRow[{p1, p2}], Style["Label", "Subsubsection"], Top] // Panel
(* same picture *)

Legended

Legended[Panel@GraphicsRow[{p1, p2}], Placed[Style["Label", "Subsubsection"], Top]] // Panel
(* same picture *)

Show with PlotLabel

Show[GraphicsRow[{p1, p2}],  PlotLabel -> Style["Label", "Subsubsection"]] // Panel

enter image description here

$\endgroup$
  • $\begingroup$ This answer actually seems to be the most versatile. $\endgroup$ – Just Some Old Man Dec 6 '18 at 23:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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