32
$\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$
1
  • 6
    $\begingroup$ You can use Labeled $\endgroup$ Commented Sep 24, 2013 at 0:07

4 Answers 4

17
$\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$
3
  • 4
    $\begingroup$ PlotRangePadding -> {0, {0, 25}} could help avoid possible text/plot collisions. $\endgroup$ Commented Sep 24, 2013 at 0:24
  • $\begingroup$ @ssch Thanks - I figured there was a padding option, but couldn't put my finger on it. $\endgroup$ Commented Sep 24, 2013 at 0:26
  • 2
    $\begingroup$ Since PlotLabel broke in v12, I’ve switched over to this approach. $\endgroup$ Commented Sep 4, 2019 at 17:43
35
$\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$
5
  • $\begingroup$ I can't imagine how I missed this. Thanks. $\endgroup$ Commented Sep 24, 2013 at 0:36
  • 6
    $\begingroup$ @MichaelStern Easy to miss since it's not in the GraphicsRow documentation :) $\endgroup$ Commented Sep 24, 2013 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$ Commented Sep 24, 2013 at 0:50
  • 1
    $\begingroup$ As of version 12, this no longer works. Sigh. $\endgroup$ Commented May 17, 2019 at 14:47
  • $\begingroup$ Not in 12.2 either. A pity. $\endgroup$ Commented Mar 10, 2021 at 6:54
11
$\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$
11
$\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$
1
  • $\begingroup$ This answer actually seems to be the most versatile. $\endgroup$ Commented Dec 6, 2018 at 23:52

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.