# Left-aligned PlotLabel?

Is it possible to have the text generated by PlotLabel (or any other function) aligned to the left side of the plot instead of in the center?

 Labeled[Plot[Sinc[x], {x, 0, 9}], Style["plot label", "Section"], {{Top, Left}}]


Also

Panel[Plot[Sinc[x], {x, 0, 9}], Style["plot label", "Section"], {{Top, Left}},
Appearance -> "Frameless"]


• This is exactly what I was looking for. – Matthew Apr 16 '13 at 19:01
• How can I change the color? – Dinesh Shankar Mar 20 '19 at 12:54
• @Dinesh, you use Style["plot label", "Section", Blue] instead of Style["plot label", "Section"] – kglr Mar 20 '19 at 15:41

You can specify your PlotLabel to be a construct that takes a TextAlignment or Alignment option, such as Pane. For example:

Plot[Sin[x], {x, 0, 5},
PlotLabel -> Framed@Pane["This is the title", Alignment -> Left,
ImageSize -> 270], ImageSize -> 300]


The Framed isn't necessary; I just included it so you could see what was going on.

The main trick is that you need to specify the size of both the total graphic and the Pane, so that the text will align to the left edge of the graphic or the axis, as shown here.

If you don't do it this way, the Pane will indeed be left-aligned text, but it will "shrink" to fit the text and still be aligned center, like this:

Plot[Sin[x], {x, 0, 5},
PlotLabel -> Framed@Pane["This is the title", Alignment -> Left]]


As an alternative, you can bend AxesLabel to fit, by working out how wide the label will be in pixels, and then adding that amount of spacing to its left in a Row construct to make the argument to AxesLabel. This is similar in spirit to Mr.Wizard's answer but has the advantage of automation of the spacing.

With[{space =
Plot[Sinc[x], {x, 0, 10}, AxesLabel -> Row[{Spacer[space], Sinc[x]}] ]]


Obviously if you have styled the label for the plot label in some other way, you will need to adjust the argument to Rasterize accordingly.

• Nice. For some reason I didn't think Pane worked. +1! – Mr.Wizard Apr 7 '13 at 5:06

You can use Epilog to insert the plot label wherever you wish within the PlotRange.

Edit: There is a drawback to this approach. Because the title will be within the graph region, there is a possibility that the title will be appear over part of the graph of the function.

Plot[Sinc[x], {x, 0, 9},
Epilog -> Text[Style["This is where my plot label goes", {Blue, 16}],
Offset[{30, -10}, Scaled[{0, 1}]], {-1, 0}]]


In the example, the text, the title is offset 30 printer's points (30/72 in) to the right and 10 printers points (10/72 in) under the upper left corner (Scaled[{0,1}]) of the Graphic. It is left-justified, {-1,0}.

Not directly that I am aware of. You could of course fake it with spacing:

Plot[Sinc[x], {x, 0, 9}, PlotLabel -> Row@{"Text", Spacer[300]}]


Simpler may be use Column but it is not part of the Graphics object itself:

Column@{"Text", Plot[Sinc[x], {x, 0, 9}]}

• I need the label to be part of the Graphics object. The spacing option isn't very dynamic. I guess there's no "easy" way to do it. – Matthew Apr 7 '13 at 0:10
• @Matthew Fortunately there is, and I was merely ignorant. See Verbeia's answer. :-) – Mr.Wizard Apr 7 '13 at 5:07

Here is a refinement of @DavidC's approach.

We can use PlotRangeClipping->False and then stick the label outside of the plot range and still have it show up. In order to do this we need to know the ImagePadding of the plot, and the height of the plot label. Here is the plot:

plot = Plot[Sinc[x], {x, 0, 9}]


We can find out the image padding using my GraphicsInformation function. Install with:

PacletInstall[
"GraphicsInformation",
"Site" -> "http://raw.githubusercontent.com/carlwoll/GraphicsInformation/master"
];


<<GraphicsInformation


GraphicsInformation returns a list of rules:

pad = "ImagePadding" /. GraphicsInformation[plot]


{{16.1531, 1.5}, {1.5, 0.5}}

To get the size of the label, we can use Rasterize:

label = Style["Plot label", "Section"];

Rasterize[label, "BoundingBox"]


{105, 33, 27}

The second element of the list is the height in points. Now, we are ready to add the label to the plot:

Show[
plot,
Graphics @ Text[label, Offset[{-16, 10}, Scaled[{0, 1}]], {-1, -1}],
PlotRangeClipping->False,
`