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.

Why does Epilog->Inset crop the first and last letters here ("a" and "g") when FontSize is set to large values (which varies with font family):

Plot[Cos[t], {t, -32 Pi, 32 Pi}, AspectRatio -> 1/4, PlotRange -> All,
  Axes -> True, ImageSize -> 600, 
 Epilog -> 
  Inset[Graphics@
    Text[Style["a   b   c   d   e   f   g", FontSize -> 30]], {0, 0}]
 ]

This renders as:

enter image description here

Are there options or a hack which still uses Epilog -> Inset, as opposed to using Show and passing the text as Graphics (which works correctly)?

share|improve this question
add comment

2 Answers 2

up vote 13 down vote accepted

Remove Graphics inside Inset:

 Plot[Cos[t], {t, -32 Pi, 32 Pi}, AspectRatio -> 1/4, PlotRange -> All,
 Axes -> True, ImageSize -> 600, 
 Epilog -> Inset[Text[Style["a b c d e f g", FontSize -> 60]], {0, 0}]]

enter image description here

EDIT: Thanks to @Brett's comment, the following Epilog settings also work:

Inset[Style["a b c d e f g", FontSize -> 60], {0, 0}]
(* or *) Text[Style["a b c d e f g", FontSize -> 60], {0, 0}]
(* or *) Style[Text["a b c d e f g", {0, 0}], FontSize -> 60]
share|improve this answer
    
Got it thanks. 2nd question (after removing Graphics) if pos is changed to {0,-1} or lower, the text gets cropped. Any ideas? –  alancalvitti Jul 6 '12 at 2:47
    
@alancalvitti I've addressed this question in the answer I posted. For your case kguler's answer works fine (+1), but you shouldn't think that Graphics is in any way forbidden inside Inset. –  Jens Jul 6 '12 at 3:20
3  
You could just use Inset[Style[...], {0,0}] or even Text[Style[...], {0,0}] since Text as a graphics primitive is implemented using Inset these days. –  Brett Champion Jul 6 '12 at 4:21
    
Alan, thanks for the accept. As @Jens explains in his answer, PlotRangePadding is the solution to avoid cropping of inset objects. Jens, thank you for the vote. –  kguler Jul 6 '12 at 4:44
    
@Brett, added your suggestions to the answer. Thank you. –  kguler Jul 6 '12 at 8:34
add comment

Here are two possibilities to make the Inset work in exactly the form you have it right now:

  • Use the scale argument for Inset and set it to Scaled[1]
  • Use the ImageSize option for the inset Graphics and set it to Full

Both have essentially the same effect of asking the inset object to fill out the enclosing graphic fully. Since Text doesn't usually resize, it only has the effect of removing any cropping around the text, as desired. You could also just specify a fixed but sufficiently large ImageSize in the inset Graphics but that would require manual adjustment.

Here is how you'd do that for the example:

Plot[Cos[t], {t, -32 Pi, 32 Pi}, AspectRatio -> 1/4, PlotRange -> All,
  Axes -> True, ImageSize -> 600, 
 Epilog -> 
  Inset[Graphics@
    Text[Style["a   b   c   d   e   f   g", FontSize -> 30]], {0, 0}, 
   Automatic, Scaled[1]]]

Plot[Cos[t], {t, -32 Pi, 32 Pi}, AspectRatio -> 1/4, PlotRange -> All,
  Axes -> True, ImageSize -> 600, 
 Epilog -> 
  Inset[Graphics[
    Text[Style["a   b   c   d   e   f   g", FontSize -> 30]], 
    ImageSize -> Full], {0, 0}]]

You then can get additional cropping problems when the Inset position is moved too far down (or anywhere beyond the plot range). This is a different issue and can be resolved by either specifying a PlotRange that's larger than All, or (to be independent of the specific range) by adding the option PlotRangePadding:

Plot[Cos[t], {t, -32 Pi, 32 Pi}, AspectRatio -> 1/4, 
 PlotRange -> All,
 Axes -> True,
 ImageSize -> 600,
 (*  added padding to accomodate inset: *)
 PlotRangePadding -> .5,
 Epilog -> 
  Inset[Graphics[
    Text[Style["a   b   c   d   e   f   g", 
      FontSize -> 30]]], {0, -1}, Automatic, Scaled[1]]]

inset

share|improve this answer
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.