# Placing text within a plot

I want to place text within a plot. The text is always centered relative to the coordinates. How can I left-align or right-align the text relative to the coordinates? For example:

Show[
Plot[hLim1[x], {x, 0.001, 0.99},
AxesLabel -> {"Prob of Causality", "Prob of Causality Given Simul"}],
Graphics[Text[Style["X2 Function", FontSize -> 14, Red], {0.5, 0.5}]]]


centers the text at {0.5, 0.5}. How can I make the left most part of the text at {0.5, 0.5}? I have tried the TextAlignment option in Style, but it does not do it.

I have also tried the AlignmentPoint option in Graphics, but that does not change anything either.

• Check Epilog to put some text or other graphics primitives in a plot. – Öskå Jan 15 '15 at 12:12
• That seems very complicated. How does one control text alighnment with Epilog? I don't see it in the examples. Thank you. – Anthony Mannucci Jan 15 '15 at 12:22
• @AnthonyMannucci This might help mathematica.stackexchange.com/questions/22839/… – Gordon Coale Jan 15 '15 at 13:28

The answer is in the docs yet it might be useful for others so I will just drop it here. The Details and Options section of the Text documentation says:

Thus you can do the following:

Plot[x, {x, 0, 1},
Epilog -> {Text[Style["hello", 25], Scaled[{0.5, 0.5}], #], Red,
Point@{.5, .5}}, PlotLabel -> ToString@#] & /@ {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};


giving you different relative placements of the Text:

• Although the documentation only shows use of the values -1, 0, or 1; any numeric values can be used. For example, to make the spacing larger (e.g., to avoid any overlap with the curve) use larger numeric values. – Bob Hanlon Jan 15 '15 at 14:22
• @BobHanlon As the doc says: "The offsets specified need not be in the range -1 to +1." :) – Öskå Jan 15 '15 at 14:35

The third argument to Text can be useful in situations like the one you describe. Perhaps this example will give you the info you need to proceed.

align[Right] = {1, 0};
align[Center] = {0, 0};  (* default *)
align[Left] = {-1, 0};

lText = Text["Left Aligned", {0.5, 0.6}, align[Left]];
cText = Text["Centered", {0.5, 0.5}, align[Center]];
rText = Text["Right Aligned", {0.5, 0.4}, align[Right]];

txt = Graphics[{lText, cText, rText}];
plot = Plot[Sin[π t], {t, 0, 1}];

Show[plot, txt]


• mhm, we basically have the same answer. – Öskå Jan 15 '15 at 13:33
• @Öskå. Indeed -- because the 3rd argument of Text is designed to handle what the OP wants to do. But there are enough differences in the details that both might be useful to the OP or others with the same problem. – m_goldberg Jan 15 '15 at 13:40