Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
add comment

4 Answers 4

up vote 8 down vote accepted
 Labeled[Plot[Sinc[x], {x, 0, 9}], Style["plot label", "Section"], {{Top, Left}}]

enter image description here

share|improve this answer
    
This is exactly what I was looking for. –  Matthew Apr 16 '13 at 19:01
add comment

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]

enter image description here

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]]

enter image description here

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 = 
   First@ImageDimensions[Rasterize[TraditionalForm[Sinc[x]]]]}, 
 Plot[Sinc[x], {x, 0, 10}, AxesLabel -> Row[{Spacer[space], Sinc[x]}] ]]

enter image description here

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.

share|improve this answer
    
Nice. For some reason I didn't think Pane worked. +1! –  Mr.Wizard Apr 7 '13 at 5:06
add comment

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}]]

plot

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}.

share|improve this answer
add comment

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}]}
share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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